﻿using System;
using System.Data;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using HRM.HRMServiceProxy;
using HRM.BusinessLogic;

namespace HRM
{
    public partial class frmEmployeeInfo : Form
    {
        int _employeeID;
        int PremiumID = 0;
        bool isChange = false;
        EmployeeInfo _employeeInfo;
        DialogResult _dlgResult;
        EmployeeClient _wcfEployee;
        HospitalClient _wcfHospital;
        HospitalInfo _HospitalInfo;
        RoleRightInfo _listRole;
        DetailClient _wcfDetail;

        int _Type;
        byte[] _Image = null;
        Image _img = null;
        private string _FullName;
        string _SIBookNo = "";
        public string FullName
        {
            get { return _FullName; }
            set { _FullName = value; }
        }
        private string _Address;
        public string Address
        {
            get { return _Address; }
            set { _Address = value; }
        }

        private string _Telephone;
        public string Telephone
        {
            get { return _Telephone; }
            set { _Telephone = value; }
        }
        int _BranchID = 0;
        private int _departmentID;
        private int[] EmployeeID;

        public frmEmployeeInfo(int employeeID, int BranchID, int DepartmentID, int Type, RoleRightInfo ListRole)
        {

            InitializeComponent();
            txtEmployee_HospitalRegionCode.Enabled = true;
            txtEmployee_HospitalRegionCode.ReadOnly = false;
            this.KeyPreview = true;
            _dlgResult = DialogResult.Cancel;
            _departmentID = DepartmentID;
            _BranchID = BranchID;
            DateTextBox dtb1 = new DateTextBox(txtEmployee_Birthday);
            DateTextBox dtb2 = new DateTextBox(txtEmployee_IDcardDate);
            DateTextBox dtb3 = new DateTextBox(txtEmployee_BookDate);
            DateTextBox dtb4 = new DateTextBox(mtxMedicalDate);
            DateTextBox dtb5 = new DateTextBox(txtEmployee_StartDate);
            DateTextBox dtb6 = new DateTextBox(txtEmployee_EndDate);
            DateTextBox dtb7 = new DateTextBox(txtPartyDate);
            DateTextBox dtb8 = new DateTextBox(txtArmyFromDate);
            DateTextBox dtb9 = new DateTextBox(txtArmyToDate);
            try
            {
                //LoadLanguage();
                LoadMaritalStatus();
                LoadEthnic();
                LoadReligion();
                LoadNational();
                LoadStandard();
                LoadTypeOfLeaveWork();
                cboNational.Text = "Việt Nam";
                _wcfEployee = Service.Employee();
                _employeeInfo = new EmployeeInfo();
                _wcfHospital = Service.Hospital();
                _wcfDetail = Service.Detail();
                _employeeID = employeeID;
                _Type = Type;
                AddColumnAward();
                AddColumnLabourContract();
                //AddColumnPremium();
                AddColumnFamily();
                AddColumnPositionDetail();
                AddColumnCertificate();
                AddColumnWbackground();
                AddColumnComment();
                AddColumnLeaveRecord();
                AddColumnSafetyDevice();
                AddColumnEducation();
                txtEmployee_HospitalRegionCode.Text = Program.strRegionCode;
                if (_employeeID > 0)
                {
                    _employeeInfo = _wcfEployee.Employee_GetInfo(_employeeID);
                    EmployeeID = Nhanvien();
                    Info2Form();
                    txtEmployee_BookNo.Tag = _employeeInfo.SIBookNo;
                }
                else
                {
                    //Tự sinh số sổ tạm
                    //string SoSoTam = _wcfEployee.Employee_SinhSoSoTam();
                    string SoSoTam = _employeeInfo.SIBookNo;
                    txtEmployee_BookNo.Text = SoSoTam;
                    txtEmployee_BookNo.Tag = SoSoTam;
                }
                _listRole = ListRole;
                SetButtonImage();
                isChange = false;
                tab_info.TabPages.Remove(tabPage9);
                tab_info.TabPages.Remove(tabPage10);
                tab_info.TabPages.Remove(tabPage8);                
            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }
            ShowFullName();
        }

        void SetButtonImage()
        {
            if (!_listRole.Update)
            {
                this.btnEditCertificate.Image = global::HRM.Properties.Resources.app;
                this.btnEditCertificate.Text = UpdateUI.GetString("xem");

                this.btnEditComment.Image = global::HRM.Properties.Resources.app;
                this.btnEditComment.Text = UpdateUI.GetString("xem");

                this.btnEditFamily.Image = global::HRM.Properties.Resources.app;
                this.btnEditFamily.Text = UpdateUI.GetString("xem");

                this.btnEditReward.Image = global::HRM.Properties.Resources.app;
                this.btnEditReward.Text = UpdateUI.GetString("xem");

                this.btnEditWB.Image = global::HRM.Properties.Resources.app;
                this.btnEditWB.Text = UpdateUI.GetString("xem");

                this.toolStripButton5.Image = global::HRM.Properties.Resources.app;
                this.toolStripButton5.Text = UpdateUI.GetString("xem");

                this.toolStripButton2.Image = global::HRM.Properties.Resources.app;
                this.toolStripButton2.Text = UpdateUI.GetString("xem");

                this.btnPremiumEdit.Image = global::HRM.Properties.Resources.app;
                this.btnPremiumEdit.Text = UpdateUI.GetString("xem");
            }
            this.tstEmployee.Visible = true;
            this.tstGiaDinh.Visible = true;
            this.tstLuong.Visible = true;
            this.tstKinhNghiem.Visible = true;
            this.tstTrinhDo.Visible = true;
            this.tstKhenThuongKL.Visible = true;
            this.tstDanhgiaNhanxet.Visible = true;
            this.tstHDLD.Visible = true;
            this.tstDongBH.Visible = true;
            tstNgayNghiPhep.Visible = true;
            tslDaoTao.Visible = true;
        }

        private void LoadLanguage()
        {
            this.Text = UpdateUI.GetString(this.Tag.ToString());
            UpdateUI.Load_Panel(ref panel2);
            UpdateUI.Load_ToolStrip(ref tstEmployee);
            UpdateUI.Load_ToolStrip(ref tstGiaDinh);
            UpdateUI.Load_ToolStrip(ref tstLuong);
            UpdateUI.Load_ToolStrip(ref tstKinhNghiem);
            UpdateUI.Load_ToolStrip(ref tstTrinhDo);
            UpdateUI.Load_ToolStrip(ref tstKhenThuongKL);
            UpdateUI.Load_ToolStrip(ref tstDanhgiaNhanxet);
            UpdateUI.Load_ToolStrip(ref tstHDLD);
            UpdateUI.Load_ToolStrip(ref tstQuanLyVisa);
            UpdateUI.Load_ToolStrip(ref tstDongBH);
            UpdateUI.Load_TabControl(ref tab_info);
            UpdateUI.Load_ContextMenuStrip(ref cmsImage);
        }

        void LoadTypeOfLeaveWork()
        {
            TypeOfLeaveWorkClient wcfTypeOfLeaveWork = Service.TypeOfLeaveWork();
            DataTable dt = wcfTypeOfLeaveWork.TypeOfLeaveWork_GetByBranchCode(Program.strBranchCode).Tables[0];
            DataRow dr = dt.NewRow();
            dr["TypeOfLeaveWork_ID"] = 0;
            dr["TypeOfLeaveWork_Name"] = "";
            dt.Rows.InsertAt(dr, 0);
            cboTypeOfLeaveWork.DataSource = null;
            cboTypeOfLeaveWork.DisplayMember = "TypeOfLeaveWork_Name";
            cboTypeOfLeaveWork.ValueMember = "TypeOfLeaveWork_ID";
            cboTypeOfLeaveWork.DataSource = dt;
        }

        void LoadStandard()
        {
            StandardClient wcfStandard = Service.Standard();
            DataTable dt = wcfStandard.Standard_GetAll().Tables[0];
            DataRow dr = dt.NewRow();
            dr["Standard_ID"] = 0;
            dr["Standard_Name"] = "";
            dt.Rows.InsertAt(dr, 0);
            cboStandard.DataSource = null;
            cboStandard.DisplayMember = "Standard_Name";
            cboStandard.ValueMember = "Standard_ID";
            cboStandard.DataSource = dt;
        }

        private void Info2Form()
        {
            lblIndex.Text = (_index + 1).ToString() + "/" + (EmployeeID.Length).ToString();
            try
            {
                _employeeID = _employeeInfo.ID;
                txtEmployee_FisrtName.Text = _employeeInfo.FirstName;
                txtEmployee_LastName.Text = _employeeInfo.LastName;
                txtEmployee_Code.Text = _employeeInfo.Code;
                txtEmployee_Address.Text = _employeeInfo.Address;
                txtEmployee_NativeCountry.Text = _employeeInfo.NativeCountry;
                txtEmployee_Alias.Text = _employeeInfo.Alias;
                if (_employeeInfo.Education != 0)
                    cboStandard.SelectedValue = _employeeInfo.Education;
                else
                    cboStandard.SelectedValue = 0;
                txtEmployee_BankName.Text = _employeeInfo.BankName;
                txtEmployee_BankNo.Text = _employeeInfo.BankAccountNo;
                if (_employeeInfo.DateOfBirth != DateTime.MinValue)
                    txtEmployee_Birthday.Text = _employeeInfo.DateOfBirth.ToString("dd/MM/yyyy");
                txtEmployee_PlaceOfBirth.Text = _employeeInfo.PlaceOfBirth;
                txtEmployee_Phone.Text = _employeeInfo.Phone;
                cboNational.SelectedValue = _employeeInfo.Nationality;
                txtMedicalNo.Text = _employeeInfo.MedicalNo;
                mtxMedicalDate.Text = _employeeInfo.MedicalDate == DateTime.MinValue ? "" : _employeeInfo.MedicalDate.ToString("dd/MM/yyyy");
                txtMedicalPlace.Text = _employeeInfo.MedicalPlace;
                //
                txtEmployee_HospitalRegionCode.Text = _employeeInfo.MedicalRegionCode;


                _HospitalInfo = new HospitalInfo();
                _HospitalInfo = _wcfHospital.Hospital_GetInfoByCode(_employeeInfo.MedicalPlace, _employeeInfo.MedicalRegionCode);
                if (_HospitalInfo != null)
                    txtHospitalName.Text = _HospitalInfo.Name;
                txtEmployee_IDCardNo.Text = _employeeInfo.IDCardNo;
                txtEmployee_IDcardDate.Text = _employeeInfo.IDCardIssueDate == DateTime.MinValue ? "" : _employeeInfo.IDCardIssueDate.ToString("dd/MM/yyyy");
                txtEmployee_IDCardPlace.Text = _employeeInfo.IDCardIssueAuthority;
                txtEmployee_BookNo.Text = _employeeInfo.SIBookNo;
                if (_wcfDetail.Detail_CheckExistSIBookNo(_employeeInfo.SIBookNo, Program.strBranchCode))
                {
                    txtEmployee_BookNo.ReadOnly = true;
                    txtEmployee_BookNo.BackColor = Color.White;
                }
                _SIBookNo = _employeeInfo.SIBookNo;
                txtEmployee_BookDate.Text = _employeeInfo.SIBookIssueDate == DateTime.MinValue ? "" : _employeeInfo.SIBookIssueDate.ToString("dd/MM/yyyy");
                txtEmployee_BookPlace.Text = _employeeInfo.SIBookIssueAuthority;
                txtEmployee_StartDate.Text = _employeeInfo.StartDate == DateTime.MinValue ? "" : _employeeInfo.StartDate.ToString("dd/MM/yyyy");
                txtEmployee_EndDate.Text = _employeeInfo.EndDate == DateTime.MinValue ? "" : _employeeInfo.EndDate.ToString("dd/MM/yyyy");
                cboEmployee_Ethnic.SelectedValue = _employeeInfo.EthlicID;
                cboEmployee_MaritalStatus.SelectedValue = _employeeInfo.MaterialStatusID;
                cboEmployee_Religion.SelectedValue = _employeeInfo.ReligionID;
                txtPartyDate.Text = _employeeInfo.PartyDate == DateTime.MinValue ? "" : _employeeInfo.PartyDate.ToString("dd/MM/yyyy");
                txtArmyFromDate.Text = _employeeInfo.ArmyFromDate == DateTime.MinValue ? "" : _employeeInfo.ArmyFromDate.ToString("dd/MM/yyyy");
                txtArmyToDate.Text = _employeeInfo.ArmyToDate == DateTime.MinValue ? "" : _employeeInfo.ArmyToDate.ToString("dd/MM/yyyy");
                txtCulture.Text = _employeeInfo.Culture;
                txtArmyPosition.Text = _employeeInfo.ArmyPosition;
                if (_employeeInfo.UserName != "")
                {
                    txtUserName.Text = " | " + UpdateUI.GetString("tendangnhap") + ": " + _employeeInfo.UserName;
                    //btnCreateUser.Visible = false;
                    //toolStripSeparator19.Visible = false;
                }
                else
                {
                    txtUserName.Text = "";
                    //btnCreateUser.Visible = true;
                    //toolStripSeparator19.Visible = true;
                }
                if (_employeeInfo.Sex)
                    radMale.Checked = _employeeInfo.Sex;
                else
                    radFemale.Checked = true;
                if (_employeeInfo.Type)
                    radNormal.Checked = _employeeInfo.Type;
                else
                    radSpecial.Checked = true;
                rdnYes.Checked = _employeeInfo.IsOfficer;
                rdnNo.Checked = !rdnYes.Checked;
                chkResign.Checked = _employeeInfo.IsQuit;
                chkUnemployIns.Checked = _employeeInfo.UnemployIns;
                txtUnemployInsDate.Text = _employeeInfo.UnemployInsDate == DateTime.MinValue ? "" : _employeeInfo.UnemployInsDate.ToString("dd/MM/yyyy");
                txtSpecialist.Text = _employeeInfo.Specialist;
                if (_employeeInfo.LeaveWorkID != 0)
                    cboTypeOfLeaveWork.SelectedValue = _employeeInfo.LeaveWorkID;
                else
                    cboTypeOfLeaveWork.SelectedValue = 0;
                byte[] btarr = _wcfEployee.Employee_GetImage(_employeeID);


                if (btarr != null)
                {
                    using (MemoryStream ms = new MemoryStream(btarr, 0, btarr.Length))
                    {
                        ms.Write(btarr, 0, btarr.Length);
                        //Set image variable value using memory stream.
                        _img = Image.FromStream(ms, true);
                    }

                    if (_img != null)
                    {
                        picEmployee.Image = _img;
                        picEmployee.SizeMode = PictureBoxSizeMode.Zoom;
                        /*
                        if (picEmployee.Image.Width > picEmployee.Width || picEmployee.Image.Height > picEmployee.Height)
                            picEmployee.SizeMode = PictureBoxSizeMode.Zoom;
                        else
                            picEmployee.SizeMode = PictureBoxSizeMode.StretchImage;
                         */
                    }
                }
                else
                    picEmployee.Image = null;

                _Image = btarr;
                
                //hiepdh: Tính TNN, TNVK hay ko
                cboUnJobFactor.Checked = _employeeInfo.UnJobFactor;
                cboUnOverFactor.Checked = _employeeInfo.UnOverFactor;
                //

                LoadPremium();
                LoadPositionDetail(_employeeID);
                LoadLabourContract(_employeeID);
                LoadFamily(_employeeID);
                LoadCertificate(_employeeID);
                LoadWbackground(_employeeID);
                LoadComment(_employeeID);
                LoadAward(_employeeID);
                LoadVisa(_employeeID);
                LoadLeaveRecord(_employeeID);
                LoadSafetyDevice(_employeeID);
                LoadEducation(_employeeID);
            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }
            isChange = false;
        }

        private void Form2Info() //Chuyển dữ liệu vào Info
        {
            try
            {
                _employeeInfo.ID = _employeeID;
                _employeeInfo.CardNo = "";
                _employeeInfo.Code = txtEmployee_Code.Text;
                _employeeInfo.FirstName = txtEmployee_FisrtName.Text.Trim();
                _employeeInfo.LastName = txtEmployee_LastName.Text.Trim();
                _employeeInfo.Alias = txtEmployee_Alias.Text;
                _employeeInfo.Education = Convert.ToInt32(cboStandard.SelectedValue);
                _employeeInfo.DateOfBirth = UISetting.GetDate(txtEmployee_Birthday.Text);
                _employeeInfo.PlaceOfBirth = txtEmployee_PlaceOfBirth.Text;

                _employeeInfo.Address = txtEmployee_Address.Text;
                _employeeInfo.NativeCountry = txtEmployee_NativeCountry.Text;
                _employeeInfo.Phone = txtEmployee_Phone.Text;
                _employeeInfo.Nationality = Convert.ToInt32(cboNational.SelectedValue);
                _employeeInfo.Specialist = txtSpecialist.Text;
                _employeeInfo.PassportNo = "";
                _employeeInfo.PassportIssueDate = DateTime.MinValue;
                _employeeInfo.PassportExpireDate = DateTime.MinValue;

                _employeeInfo.MedicalNo = txtMedicalNo.Text;
                _employeeInfo.MedicalDate = UISetting.GetDate(mtxMedicalDate.Text);
                _employeeInfo.MedicalPlace = txtMedicalPlace.Text;

                _employeeInfo.MedicalRegionCode = txtEmployee_HospitalRegionCode.Text;

                _employeeInfo.IDCardNo = txtEmployee_IDCardNo.Text;
                _employeeInfo.IDCardIssueDate = UISetting.GetDate(txtEmployee_IDcardDate.Text);
                _employeeInfo.IDCardIssueAuthority = txtEmployee_IDCardPlace.Text;

                _employeeInfo.SIBookNo = txtEmployee_BookNo.Text;
                _employeeInfo.SIBookIssueDate = UISetting.GetDate(txtEmployee_BookDate.Text);
                _employeeInfo.SIBookIssueAuthority = txtEmployee_BookPlace.Text;
               
                _employeeInfo.EthlicID = Convert.ToInt32(cboEmployee_Ethnic.SelectedValue);
                _employeeInfo.MaterialStatusID = Convert.ToInt32(cboEmployee_MaritalStatus.SelectedValue);
                _employeeInfo.ReligionID = Convert.ToInt32(cboEmployee_Religion.SelectedValue);
                _employeeInfo.BankName = txtEmployee_BankName.Text;
                _employeeInfo.BankAccountNo = txtEmployee_BankNo.Text;
                _employeeInfo.StartDate = UISetting.GetDate(txtEmployee_StartDate.Text);
                _employeeInfo.EndDate = UISetting.GetDate(txtEmployee_EndDate.Text);
                _employeeInfo.Description = "";
                _employeeInfo.Sex = radMale.Checked;
                _employeeInfo.IsOfficer = rdnYes.Checked;
                _employeeInfo.IsQuit = chkResign.Checked;
                _employeeInfo.Type = radNormal.Checked;
                _employeeInfo.LeaveWorkID = Convert.ToInt32(cboTypeOfLeaveWork.SelectedValue);
                _employeeInfo.UnemployIns = chkUnemployIns.Checked;
                _employeeInfo.UnemployInsDate = UISetting.GetDate(txtUnemployInsDate.Text);
                _employeeInfo.Culture = txtCulture.Text;
                _employeeInfo.PartyDate = UISetting.GetDate(txtPartyDate.Text);
                _employeeInfo.ArmyFromDate = UISetting.GetDate(txtArmyFromDate.Text);
                _employeeInfo.ArmyToDate = UISetting.GetDate(txtArmyToDate.Text);
                _employeeInfo.ArmyPosition = txtArmyPosition.Text;
                _employeeInfo.BranchID = Program.intBranchID;
                //hiepdh: Tinh TNN, TNVK hay ko
                _employeeInfo.UnOverFactor = cboUnOverFactor.Checked;
                _employeeInfo.UnJobFactor = cboUnJobFactor.Checked;


                if (picEmployee.ImageLocation != null)
                {
                    FileStream f = new FileStream(picEmployee.ImageLocation, FileMode.Open);
                    _Image = new byte[f.Length];
                    f.Read(_Image, 0, (int)f.Length);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }
        }

        bool CheckValid() //Kiểm tra dữ liệu nhập
        {

            DateTime DateValue;          

            if (txtEmployee_LastName.Text.Trim().Length == 0 || txtEmployee_FisrtName.Text.Trim().Length == 0)
            {
                txtEmployee_LastName.Focus();
                MessageBox.Show(UpdateUI.GetString("chuanhapho"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            if (!radMale.Checked && !radFemale.Checked)
            {
                MessageBox.Show(UpdateUI.GetString("chuachongioitinh"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            if (UISetting.GetDate(txtEmployee_Birthday.Text) == DateTime.MinValue)
            {
                txtEmployee_Birthday.Focus();
                MessageBox.Show(UpdateUI.GetString("ngaysinhkhonghople"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            if (txtEmployee_NativeCountry.Text.Trim().Length == 0)
            {
                txtEmployee_NativeCountry.Focus();
                MessageBox.Show("Chưa nhập hộ khẩu thường trú", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            if (txtEmployee_IDCardNo.Text.Trim().Length == 0)
            {
                txtEmployee_IDCardNo.Focus();
                MessageBox.Show("Chưa nhập số Chứng minh thư nhân dân", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            else if (txtEmployee_IDCardNo.Text.Trim().Length != 9 && txtEmployee_IDCardNo.Text.Trim().Length != 12)
            {
                txtEmployee_IDCardNo.Focus();
                MessageBox.Show("Số Chứng minh thư nhân dân phải đủ 9 hoặc 12 ký tự", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            else
            {
                Int64 CMTTmp = 0;
                Int64.TryParse(txtEmployee_IDCardNo.Text.Trim(), out CMTTmp);
                if (CMTTmp == 0)
                {
                    MessageBox.Show("Số Chứng minh thư nhân dân phải đủ 9 hoặc 12 ký tự và đúng định dạng số", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return false;
                }
                ////Bo trung CMT, thay = so so tam tu tang, 21/06/2012, hiepdh
                //else
                //{
                //    //Check trùng CMT
                //    if (_wcfEployee != null)
                //    {
                //        if (_wcfEployee.Employee_CheckIDCard(_employeeID, txtEmployee_IDCardNo.Text.Trim(), _BranchID) > 0)
                //        {
                //            MessageBox.Show("Số Chứng minh thư nhân dân này đã được sử dụng cho 1 nhân sự khác", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //            return false;
                //        }
                //    }
                //}
            }

            //Kiểm tra nhập số sổ
            //if (txtEmployee_BookNo.Text.Trim().Length == 0)
            //{
            //    txtEmployee_BookNo.Focus();
            //    MessageBox.Show("Chưa nhập số sổ BHXH", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //    return false;
            //}
            //else if (txtEmployee_BookNo.Text.Trim().Length != 10)
            //{
            //    MessageBox.Show("Số sổ BHXH phải đủ 10 ký tự");
            //    txtEmployee_BookNo.Focus();
            //    return false;
            //}
            //else if (txtEmployee_BookNo.Tag != null)
            //{
            //    if (txtEmployee_BookNo.Tag.ToString().ToUpper() != txtEmployee_BookNo.Text.Trim().ToUpper())
            //    {
            //        int so = 0;
            //        Int32.TryParse(txtEmployee_BookNo.Tag.ToString(), out so);
            //        if (so == 0)
            //        {
            //            MessageBox.Show("Số sổ tạm chỉ được thay đổi bằng số sổ thật");
            //            txtEmployee_BookNo.Focus();
            //            return false;
            //        }
            //    }
            //}

            //Nếu nhập số sổ thật thì lưu, ko thì tự sinh số sổ tạm
            if (txtEmployee_BookNo.Text.Trim().Length > 0)
            {
                if (txtEmployee_BookNo.Text.Trim().Length != 10)
                {
                    MessageBox.Show("Số sổ BHXH phải đủ 10 ký tự");
                    txtEmployee_BookNo.Focus();
                    return false;
                }
                else if (txtEmployee_BookNo.Tag != null)
                {
                    if (txtEmployee_BookNo.Tag.ToString().ToUpper() != txtEmployee_BookNo.Text.Trim().ToUpper())
                    {
                        Int64 so = 0;
                        Int64.TryParse(txtEmployee_BookNo.Text.ToString(), out so);
                        if (so == 0)
                        {
                            MessageBox.Show("Số sổ tạm chỉ được thay đổi bằng số sổ thật");
                            txtEmployee_BookNo.Focus();
                            return false;
                        }
                    }
                }
            }


            if (txtEmployee_HospitalRegionCode.Text.Length == 0)
            {
                txtMedicalPlace.Focus();
                MessageBox.Show("Chưa nhập nơi khám chữa bệnh", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            if (txtMedicalPlace.Text.Trim().Length == 0)
            {
                txtMedicalPlace.Focus();
                MessageBox.Show("Chưa nhập nơi khám chữa bệnh", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }

            if (!_wcfHospital.Hospital_CheckExist(txtMedicalPlace.Text.Trim(), txtEmployee_HospitalRegionCode.Text))
            {
                txtMedicalPlace.Focus();
                MessageBox.Show("Nơi khám chữa bệnh không hợp lệ", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }

            if (txtEmployee_IDcardDate.Text.Length == 0)
                txtEmployee_IDcardDate.Text = "";
            else
            {
                if (!DateTime.TryParseExact(txtEmployee_IDcardDate.Text, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out DateValue))
                {
                    txtEmployee_IDcardDate.Focus();
                    MessageBox.Show(UpdateUI.GetString("ngaycapCMNDkhonghople"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return false;
                }
            }

            if (txtEmployee_BookDate.Text.Length == 0)
                txtEmployee_BookDate.Text = "";
            else
            {
                if (!DateTime.TryParseExact(txtEmployee_BookDate.Text, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out DateValue))
                {
                    txtEmployee_BookDate.Focus();
                    MessageBox.Show(UpdateUI.GetString("ngaycapsobhkhonghople"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return false;
                }
            }

            //if (!DateTime.TryParseExact(txtEmployee_StartDate.Text, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out DateValue))
            //{
            //    txtEmployee_StartDate.Focus();
            //    MessageBox.Show(UpdateUI.GetString("ngaybatdauvaocongtykhonghople"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //    return false;
            //}

            if (txtEmployee_EndDate.Text.Length == 0)
                txtEmployee_EndDate.Text = "";
            else
            {
                if (!DateTime.TryParseExact(txtEmployee_EndDate.Text, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out DateValue))
                {
                    txtEmployee_EndDate.Focus();
                    MessageBox.Show(UpdateUI.GetString("ngaythoivieckhonghople"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return false;
                }
                else
                {
                    //if(_employeeID>0)
                    //update PD_Isactive=false;
                }
            }
            //if (cboStandard.Text.Length == 0)
            //{
            //    cboStandard.Focus();
            //    MessageBox.Show("Chưa nhập trình độ", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //    return false;
            //}
            if (!rdnYes.Checked && !rdnNo.Checked)
            {
                MessageBox.Show(UpdateUI.GetString("chuachonkieugiolam"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }           
            return true;
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            if (!_listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_employeeInfo.ID == 0)
            {
                MessageBox.Show("Bạn muốn lưu trước khi tạo mới");
                return;
            }

            _employeeInfo.ID = 0;
            _employeeID = 0;
            radMale.Checked = false;
            radFemale.Checked = false;
            rdnNo.Checked = false;
            rdnYes.Checked = true;
            txtEmployee_Code.Text = "";
            txtEmployee_FisrtName.Text = "";
            txtEmployee_LastName.Text = "";
            txtEmployee_Address.Text = "";
            txtEmployee_Alias.Text = "";
            txtEmployee_BankName.Text = "";
            txtEmployee_BankNo.Text = "";
            txtEmployee_BookNo.Text = "";
            txtEmployee_BookPlace.Text = "";
            txtEmployee_Birthday.Text = "";
            txtEmployee_BookDate.Text = "";

            txtEmployee_PlaceOfBirth.Text = "";
            txtEmployee_NativeCountry.Text = "";
            txtEmployee_StartDate.Text = "";
            txtEmployee_EndDate.Text = "";
            txtEmployee_IDcardDate.Text = "";
            txtEmployee_IDCardNo.Text = "";
            txtEmployee_Phone.Text = "";
            txtEmployee_IDCardPlace.Text = "";
            txtEmployee_Birthday.Text = "";
            txtEmployee_BookDate.Text = "";
            txtEmployee_IDcardDate.Text = "";
            txtUserName.Text = "";            
            // btnCreateUser.Visible = true;
            //btnCreateUser.Enabled = false;
            LoadPremium();
            LoadPositionDetail(_employeeID);
            LoadLabourContract(_employeeID);
            LoadFamily(_employeeID);
            LoadCertificate(_employeeID);
            LoadWbackground(_employeeID);
            LoadComment(_employeeID);
            LoadAward(_employeeID);
            LoadVisa(_employeeID);

        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!CheckValid())
            {
                isChange = true;
                return;
            }
            PositionDetailClient _wcfPD = Service.PositionDetail();
            if (_employeeID > 0) //Update
            {

                if (!_listRole.Update)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyencapnhat"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                Form2Info();
                //Kiểm tra nếu số sổ đã có phát sinh trong table HRM_BHDetail thì không cho cập nhật
                if (_SIBookNo != _employeeInfo.SIBookNo)
                {
                    if (_wcfDetail.Detail_CheckExistSIBookNo(_employeeInfo.SIBookNo,Program.strBranchCode))
                    {
                        MessageBox.Show("Số sổ này đã có phát sinh, bạn phải sử dụng chức năng đổi sổ BHXH!", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txtEmployee_BookNo.Focus();
                        txtEmployee_BookNo.SelectAll();
                        return;
                    }
                }
                if (txtEmployee_Code.Text.Trim().Length != 0)
                {
                    //Nếu số thẻ không trống thì kiểm tra
                    if (_wcfEployee.Employee_CheckExist(_employeeID, txtEmployee_Code.Text.Trim(), Program.intBranchID) > 0)
                    {
                        txtEmployee_Code.Focus();
                        MessageBox.Show(UpdateUI.GetString("datontaimanhanvien"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
                if (_wcfEployee.Employee_Update(_employeeInfo))
                {
                    //Update so bao hiem neu thay doi so so:
                    //if (_SIBookNo != _employeeInfo.SIBookNo)
                    //    _wcfEployee.Employee_UpdateSIBookNo(_SIBookNo, _employeeInfo.SIBookNo);

                    if (_Image != null)
                    {
                        try
                        {
                            if (!_wcfEployee.Employee_UpdateImage(_employeeInfo.ID, _Image))
                            {
                                MessageBox.Show(UpdateUI.GetString("capnhatkhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                isChange = true;
                                _dlgResult = DialogResult.Cancel;
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(UpdateUI.GetString("dungluonganhqualon"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            isChange = true;
                            _dlgResult = DialogResult.Cancel;
                            return;
                        }
                    }
                    else
                    {
                        if (!_wcfEployee.Employee_UpdateImageNull(_employeeInfo.ID))
                        {
                            MessageBox.Show(UpdateUI.GetString("capnhatkhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            isChange = true;
                            _dlgResult = DialogResult.Cancel;
                            return;
                        }
                    }
                    Program.taskbarNotifier.Show(UpdateUI.GetString("thongbao"), UpdateUI.GetString("capnhatthanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                    isChange = false;
                    _dlgResult = DialogResult.OK;
                    LocalDB.dtTableEmployee = _wcfEployee.Employee_GetAllWithBranch(Program.intBranchID).Tables[0];
                }
                else
                {
                    MessageBox.Show(UpdateUI.GetString("capnhatkhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                
            }
            else // Insert
            {
                if (!_listRole.Create)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                Form2Info();
                if (txtEmployee_Code.Text.Trim().Length != 0)
                {
                    //Nếu số thẻ không trống thì kiểm tra
                    if (_wcfEployee.Employee_CodeExist(_employeeID, txtEmployee_Code.Text.Trim()) > 0)
                    {
                        txtEmployee_Code.Focus();
                        MessageBox.Show(UpdateUI.GetString("datontaimanhanvien"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
                FullName = _employeeInfo.LastName + " " + _employeeInfo.FirstName;
                Address = _employeeInfo.Address;
                Telephone = _employeeInfo.Phone;
                if (_wcfEployee.Employee_CheckExist2(Program.intBranchID, _employeeInfo.DateOfBirth, _employeeInfo.IDCardNo, _employeeInfo.SIBookNo) > 0)
                {
                    MessageBox.Show("Đã tồn tại nhân viên này trong hệ thống, hãy kiểm tra lại");
                    return;
                }
                _employeeInfo.ID = _wcfEployee.Employee_Insert(_employeeInfo);
                _employeeID = _employeeInfo.ID;
                if (_employeeID > 0)
                {
                    //btnCreateUser.Enabled = true;

                    if (_Image != null)
                    {
                        _wcfEployee.Employee_UpdateImage(_employeeInfo.ID, _Image);
                    }

                    //hiepdh: 26/08 Gán số sổ tạm sau khi đã insert thông tin nhân sự và tạo số sổ tạm
                    _employeeInfo = _wcfEployee.Employee_GetInfo(_employeeID);
                    string SoSoTam = _employeeInfo.SIBookNo;
                    txtEmployee_BookNo.Text = SoSoTam;
                    txtEmployee_BookNo.Tag = SoSoTam;

                    //
                    Program.taskbarNotifier.Show(UpdateUI.GetString("thongbao"), UpdateUI.GetString("themmoithanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                    isChange = false;
                    _dlgResult = DialogResult.OK;
                    LocalDB.dtTableEmployee = _wcfEployee.Employee_GetAllWithBranch(Program.intBranchID).Tables[0];
                }
                else
                {
                    MessageBox.Show(UpdateUI.GetString("themmoikhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    isChange = true;
                }                
            }
        }
        private void LoadMaritalStatus()
        {
            try
            {
                MaritalStatusClient wcfMaritalStatus = Service.MaritalStatus();
                cboEmployee_MaritalStatus.DisplayMember = "MaritalStatus_Name";
                cboEmployee_MaritalStatus.ValueMember = "MaritalStatus_ID";
                cboEmployee_MaritalStatus.DataSource = wcfMaritalStatus.MaritalStatus_GetAll().Tables[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }
        }
        private void LoadEthnic()
        {
            try
            {
                EthnicClient wcfEthnic = Service.Ethnic();
                cboEmployee_Ethnic.DisplayMember = "Ethnic_Name";
                cboEmployee_Ethnic.ValueMember = "Ethnic_ID";
                cboEmployee_Ethnic.DataSource = wcfEthnic.Ethnic_GetAll().Tables[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }
        }
        private void LoadReligion()
        {
            try
            {
                ReligionClient wcfReligion = Service.Religion();
                cboEmployee_Religion.DisplayMember = "Religion_Name";
                cboEmployee_Religion.ValueMember = "Religion_ID";
                cboEmployee_Religion.DataSource = wcfReligion.Religion_GetAll().Tables[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }
        }
        private void LoadNational()
        {
            try
            {
                NationalClient wcfNational = Service.National();
                cboNational.DisplayMember = "National_Name";
                cboNational.ValueMember = "National_ID";
                cboNational.DataSource = wcfNational.National_GetAll().Tables[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void frmEmployeeInfo_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_employeeInfo.ID == 0)
            {
                return;
            }
            if (dgvPosition.Rows.Count == 0)
            {
                if (MessageBox.Show(UpdateUI.GetString("nhanvienkhongthuocbophan"), UIParamater.TitleProject, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    e.Cancel = true;
                    tab_info.SelectedTab = tbpPositionDetail;
                    btnNewPositionDetail_Click(null, null);
                }
            }
            else
            {
                if (isChange)
                {
                    if (MessageBox.Show(UpdateUI.GetString("bandathaydoidulieu") + "\n" + UpdateUI.GetString("coluutruockhithoatkhong"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        btnSave_Click(null, null);
                        if (isChange)
                            e.Cancel = true;
                        else
                            e.Cancel = false;
                    }
                }
            }
            this.DialogResult = _dlgResult;
        }
        private void DataChanged(object sender, EventArgs e)
        {
            isChange = true;
        }
        private void frmEmployeeInfo_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Escape:
                    btnCancel_Click(null, null);
                    break;
                case Keys.F3:
                    btnSave_Click(null, null);
                    break;
                case Keys.Enter:
                    if (!e.Alt && !e.Control)
                    {
                        this.ProcessTabKey(!e.Shift);
                        e.Handled = true;
                    }
                    break;
                case Keys.Home:
                    btnFirst_Click(null, null);
                    break;
                case Keys.PageUp:
                    btnBack_Click(null, null);
                    break;
                case Keys.PageDown:
                    btnNext_Click(null, null);
                    break;
                case Keys.End:
                    btnLast_Click(null, null);
                    break;
            }
        }
        private void btnLabourContractAdd_Click(object sender, EventArgs e)
        {
            if (!_listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_employeeInfo.ID == 0)
            {
                MessageBox.Show("Bạn cần phải lưu thông tin nhân viên này trước!", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            Form f = new frmLabourContractInfo(0, _employeeID, _listRole);
            if (f.ShowDialog(this) == DialogResult.OK)
            {
                LoadLabourContract(_employeeID);
            }
        }
        private void btnLabourContractEdit_Click(object sender, EventArgs e)
        {
            if (dgvLabourContract.SelectedRows.Count > 0)
            {
                if (_listRole.Update || _listRole.View)
                {
                    Form f = new frmLabourContractInfo(Convert.ToInt32(dgvLabourContract.CurrentRow.Cells["LC_ID"].Value), _employeeID, _listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        LoadLabourContract(_employeeID);
                    }
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);

            }
        }
        private void btnLabourContractDelete_Click(object sender, EventArgs e)
        {
            if (dgvLabourContract.SelectedRows.Count > 0)
            {
                if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    LabourContractClient wcfLC = Service.LabourContract();
                    if (wcfLC.LabourContract_Delete(Convert.ToInt32(dgvLabourContract.CurrentRow.Cells["LC_ID"].Value)))
                    {
                        Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                        LoadLabourContract(_employeeID);
                    }
                    else
                    {
                        MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }

        private void AddColumnLabourContract()
        {
            UISetting.AddColumn(ref dgvLabourContract, "LC_ID", "Mã chính", "C", 1, false, true);
            UISetting.AddColumn(ref dgvLabourContract, "LC_EmployeeID", "Mã Nhân viên", "C", 10, false, true);
            UISetting.AddColumn(ref dgvLabourContract, "LC_IsActive", "", "C", 10, false, true);
            UISetting.AddColumn(ref dgvLabourContract, "LC_No", UpdateUI.GetString("sohopdong"), "C", 100, true, true);
            UISetting.AddColumn(ref dgvLabourContract, "LC_Date", UpdateUI.GetString("ngayky"), "C", 120, true, true);
            UISetting.AddColumn(ref dgvLabourContract, "ContractType_Name", UpdateUI.GetString("loaihopdong"), "", 120, true, true);
            UISetting.AddColumn(ref dgvLabourContract, "LC_BeginDate", UpdateUI.GetString("ngaybatdau"), "C", 100, true, true);
            UISetting.AddColumn(ref dgvLabourContract, "LC_FinishDate", UpdateUI.GetString("ngayketthuc"), "C", 100, true, true);
            UISetting.AddColumn(ref dgvLabourContract, "LC_Salary", UpdateUI.GetString("mucluong"), "R", 100, true, true);
            UISetting.AddColumn(ref dgvLabourContract, "ContractType_Insurance", UpdateUI.GetString("bhxh"), "R", 100, true, true);
            UISetting.AddColumn(ref dgvLabourContract, "ContractType_Probation", UpdateUI.GetString("tyleluong"), "R", 130, true, true);
        }
        private void LoadLabourContract(int EmployeeID)
        {
            try
            {
                LabourContractClient wcfLC = Service.LabourContract();
                DataSet ds = wcfLC.LabourContract_GetWithEmployee(EmployeeID);
                dgvLabourContract.Rows.Clear();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    dgvLabourContract.Rows.Insert(i, 1);
                    dgvLabourContract.Rows[i].Cells["LC_ID"].Value = ds.Tables[0].Rows[i]["LC_ID"].ToString();
                    dgvLabourContract.Rows[i].Cells["LC_EmployeeID"].Value = ds.Tables[0].Rows[i]["LC_EmployeeID"].ToString();
                    dgvLabourContract.Rows[i].Cells["LC_IsActive"].Value = ds.Tables[0].Rows[i]["LC_IsActive"].ToString();
                    dgvLabourContract.Rows[i].Cells["LC_No"].Value = ds.Tables[0].Rows[i]["LC_No"].ToString();
                    dgvLabourContract.Rows[i].Cells["LC_Salary"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LC_Salary"]).ToString("#,##0");
                    if (ds.Tables[0].Rows[i]["LC_Date"] != DBNull.Value)
                        dgvLabourContract.Rows[i].Cells["LC_Date"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["LC_Date"]).ToString("dd/MM/yyyy");
                    dgvLabourContract.Rows[i].Cells["ContractType_Name"].Value = ds.Tables[0].Rows[i]["ContractType_Name"].ToString();
                    
                    dgvLabourContract.Rows[i].Cells["ContractType_Insurance"].Value = ds.Tables[0].Rows[i]["ContractType_Insurance"] != DBNull.Value ? Convert.ToDecimal(ds.Tables[0].Rows[i]["ContractType_Insurance"]).ToString("#,##0") : "0";
                    dgvLabourContract.Rows[i].Cells["ContractType_Probation"].Value = ds.Tables[0].Rows[i]["ContractType_Probation"] != DBNull.Value ? Convert.ToDecimal(ds.Tables[0].Rows[i]["ContractType_Probation"]).ToString("#,##0") : "0";
                    
                    if (ds.Tables[0].Rows[i]["LC_BeginDate"] != DBNull.Value)
                        dgvLabourContract.Rows[i].Cells["LC_BeginDate"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["LC_BeginDate"]).ToString("dd/MM/yyyy");
                    if (ds.Tables[0].Rows[i]["LC_FinishDate"] != DBNull.Value)
                        dgvLabourContract.Rows[i].Cells["LC_FinishDate"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["LC_FinishDate"]).ToString("dd/MM/yyyy");

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }
        }

        private void AddColumnFamily()
        {
            UISetting.AddColumn(ref dgvFamily, "Family_ID", "Mã chính", "C", 1, false, true);
            UISetting.AddColumn(ref dgvFamily, "Family_EmployeeID", "Mã Nhân viên", "C", 10, false, true);
            UISetting.AddColumn(ref dgvFamily, "Family_Name", UpdateUI.GetString("ten"), "C", 130, true, true);
            UISetting.AddColumn(ref dgvFamily, "Family_Occupation", UpdateUI.GetString("nghenghiep"), "", 130, true, true);
            UISetting.AddColumn(ref dgvFamily, "Family_Relationship", UpdateUI.GetString("quanhe"), "", 100, true, true);
            UISetting.AddColumn(ref dgvFamily, "Family_BirthYear", "Năm sinh", "R", 100, true, true);
            UISetting.AddColumn(ref dgvFamily, "Family_Address", UpdateUI.GetString("diachi"), "L", 130, true, true);
            UISetting.AddColumn(ref dgvFamily, "Family_IsDependent", UpdateUI.GetString("phuthuoc"), "C", 100, true, true);
        }
        private void LoadFamily(int EmPloyeeID)
        {
            try
            {
                FamilyClient wcfFamily = Service.Family();
                DataSet ds = wcfFamily.Family_GetWithEmployee(EmPloyeeID);
                dgvFamily.Rows.Clear();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    dgvFamily.Rows.Insert(i, 1);
                    dgvFamily.Rows[i].Cells["Family_ID"].Value = ds.Tables[0].Rows[i]["Family_ID"].ToString();
                    dgvFamily.Rows[i].Cells["Family_EmployeeID"].Value = ds.Tables[0].Rows[i]["Family_EmployeeID"].ToString();
                    dgvFamily.Rows[i].Cells["Family_Name"].Value = ds.Tables[0].Rows[i]["Family_Name"].ToString();
                    dgvFamily.Rows[i].Cells["Family_Occupation"].Value = ds.Tables[0].Rows[i]["Family_Occupation"].ToString();
                    dgvFamily.Rows[i].Cells["Family_Relationship"].Value = ds.Tables[0].Rows[i]["Family_Relationship"].ToString();
                    dgvFamily.Rows[i].Cells["Family_BirthYear"].Value = ds.Tables[0].Rows[i]["Family_BirthYear"].ToString();
                    dgvFamily.Rows[i].Cells["Family_Address"].Value = ds.Tables[0].Rows[i]["Family_Address"].ToString();
                    dgvFamily.Rows[i].Cells["Family_IsDependent"].Value = ds.Tables[0].Rows[i]["Family_IsDependent"].ToString();

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }
        }

        private void AddColumnCertificate()
        {
            UISetting.AddColumn(ref dgvCertificate, "Certificate_ID", "Mã chính", "C", 1, false, true);
            UISetting.AddColumn(ref dgvCertificate, "Certificate_EmployeeID", "Mã Nhân viên", "C", 10, false, true);
            UISetting.AddColumn(ref dgvCertificate, "Certificate_Name", UpdateUI.GetString("ten"), "C", 130, true, true);
            UISetting.AddColumn(ref dgvCertificate, "Certificate_Speciality", UpdateUI.GetString("chuyennganh"), "", 140, true, true);
            UISetting.AddColumn(ref dgvCertificate, "Certificate_AuthorityIssue", UpdateUI.GetString("noicap"), "", 130, true, true);
            UISetting.AddColumn(ref dgvCertificate, "Certificate_IssueDate", UpdateUI.GetString("ngaycap"), "", 100, true, true);
            UISetting.AddColumn(ref dgvCertificate, "Certificate_Grade", "Xếp loại", "", 100, true, true);
            UISetting.AddColumn(ref dgvCertificate, "Certificate_Kind", "H.Thức đào tạo", "", 130, true, true);
            UISetting.AddColumn(ref dgvCertificate, "Certificate_Description", "Ghi chú", "", 100, true, true);
        }
        private void LoadCertificate(int EmPloyeeID)
        {
            try
            {
                CertificateClient wcfCertificate = Service.Certificate();
                DataSet ds = wcfCertificate.Certificate_GetWithEmployee(EmPloyeeID);
                dgvCertificate.Rows.Clear();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    dgvCertificate.Rows.Insert(i, 1);
                    dgvCertificate.Rows[i].Cells["Certificate_ID"].Value = ds.Tables[0].Rows[i]["Certificate_ID"].ToString();
                    dgvCertificate.Rows[i].Cells["Certificate_EmployeeID"].Value = ds.Tables[0].Rows[i]["Certificate_EmployeeID"].ToString();
                    dgvCertificate.Rows[i].Cells["Certificate_Name"].Value = ds.Tables[0].Rows[i]["Certificate_Name"].ToString();
                    dgvCertificate.Rows[i].Cells["Certificate_AuthorityIssue"].Value = ds.Tables[0].Rows[i]["Certificate_AuthorityIssue"].ToString();
                    dgvCertificate.Rows[i].Cells["Certificate_Grade"].Value = ds.Tables[0].Rows[i]["Certificate_Grade"].ToString();
                    dgvCertificate.Rows[i].Cells["Certificate_Speciality"].Value = ds.Tables[0].Rows[i]["Certificate_Speciality"].ToString();
                    dgvCertificate.Rows[i].Cells["Certificate_Kind"].Value = ds.Tables[0].Rows[i]["Certificate_Kind"].ToString();
                    dgvCertificate.Rows[i].Cells["Certificate_Description"].Value = ds.Tables[0].Rows[i]["Certificate_Description"].ToString();
                    if (ds.Tables[0].Rows[i]["Certificate_IssueDate"] != DBNull.Value)
                        dgvCertificate.Rows[i].Cells["Certificate_IssueDate"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["Certificate_IssueDate"]).ToString("dd/MM/yyyy");
                    else
                        dgvCertificate.Rows[i].Cells["Certificate_IssueDate"].Value = "";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }

        }

        private void AddColumnWbackground()
        {
            UISetting.AddColumn(ref dgvBackGround, "WB_ID", "", "C", 1, false, true);
            UISetting.AddColumn(ref dgvBackGround, "WB_EmployeeID", "", "C", 1, false, true);
            UISetting.AddColumn(ref dgvBackGround, "WB_CompanyName", UpdateUI.GetString("ten"), "", 150, true, true);
            UISetting.AddColumn(ref dgvBackGround, "WB_Position", UpdateUI.GetString("chucvu"), "", 130, true, true);
            UISetting.AddColumn(ref dgvBackGround, "WB_StartDate", UpdateUI.GetString("tuthangnam"), "C", 120, true, true);
            UISetting.AddColumn(ref dgvBackGround, "WB_EndDate", UpdateUI.GetString("denthangnam"), "C", 120, true, true);
            UISetting.AddColumn(ref dgvBackGround, "WB_Description", UpdateUI.GetString("ghichu"), "L", 250, true, true);
        }
        private void LoadWbackground(int EmPloyeeID)
        {
            try
            {
                //WorkingBackgroundClient wcfWBackground = Service.WorkingBackground();
                //DataSet ds = wcfWBackground.WorkingBackground_GetWithEmployee(EmPloyeeID);
                DataSet ds = WorkingBackground_Controller.Instance().WorkingBackground_GetWithEmployee(EmPloyeeID);

                dgvBackGround.Rows.Clear();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    dgvBackGround.Rows.Insert(i, 1);
                    dgvBackGround.Rows[i].Cells["WB_ID"].Value = ds.Tables[0].Rows[i]["WB_ID"].ToString();
                    dgvBackGround.Rows[i].Cells["WB_EmployeeID"].Value = ds.Tables[0].Rows[i]["WB_EmployeeID"].ToString();
                    dgvBackGround.Rows[i].Cells["WB_CompanyName"].Value = ds.Tables[0].Rows[i]["WB_CompanyName"].ToString();
                    dgvBackGround.Rows[i].Cells["WB_Position"].Value = ds.Tables[0].Rows[i]["WB_Position"].ToString();
                    dgvBackGround.Rows[i].Cells["WB_Description"].Value = ds.Tables[0].Rows[i]["WB_Description"].ToString();
                    if (ds.Tables[0].Rows[i]["WB_StartDate"] != DBNull.Value)
                        dgvBackGround.Rows[i].Cells["WB_StartDate"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["WB_StartDate"]).ToString("MM/yyyy");
                    else
                        dgvBackGround.Rows[i].Cells["WB_StartDate"].Value = "";
                    if (ds.Tables[0].Rows[i]["WB_EndDate"] != DBNull.Value)
                        dgvBackGround.Rows[i].Cells["WB_EndDate"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["WB_EndDate"]).ToString("MM/yyyy");
                    else
                        dgvBackGround.Rows[i].Cells["WB_EndDate"].Value = "";

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }
        }

        private void AddColumnPositionDetail()
        {
            UISetting.AddColumn(ref dgvPosition, "PD_ID", "", "C", 1, false, true);
            UISetting.AddColumn(ref dgvPosition, "PD_PositionID", "", "C", 1, false, true);
            UISetting.AddColumn(ref dgvPosition, "PD_EmployeeID", "", "C", 1, false, true);
            UISetting.AddColumn(ref dgvPosition, "PD_DepartmentID", "", "", 1, false, true);
            UISetting.AddColumn(ref dgvPosition, "PD_IsActive", "", "", 100, false, true);
            UISetting.AddColumn(ref dgvPosition, "DepartmentName", UpdateUI.GetString("phongban"), "", 130, true, true);
            UISetting.AddColumn(ref dgvPosition, "PositionName", UpdateUI.GetString("chucvu"), "", 130, true, true);
            UISetting.AddColumn(ref dgvPosition, "PD_BeginDate", "Từ tháng/năm", "C", 110, true, true);
            UISetting.AddColumn(ref dgvPosition, "PD_EndDate", "Đến tháng/năm", "C", 110, true, true);
            UISetting.AddColumn(ref dgvPosition, "PD_BasicFactor", "HSL CB", "R", 100, true, true);
            UISetting.AddColumn(ref dgvPosition, "PD_PositionFactor", "HSL CV", "R", 100, true, true);
            UISetting.AddColumn(ref dgvPosition, "PD_BasicSalary", UpdateUI.GetString("tienluongcoban"), "R", 130, true, true);
            UISetting.AddColumn(ref dgvPosition, "PD_PositionAllowance", UpdateUI.GetString("phucapchucvu"), "R", 110, true, true);
            UISetting.AddColumn(ref dgvPosition, "PD_LunchAllowance", UpdateUI.GetString("phucapantrua"), "R", 110, true, true);
            UISetting.AddColumn(ref dgvPosition, "PD_TelephoneAllowance", UpdateUI.GetString("phucapdienthoai"), "R", 110, true, true);
            UISetting.AddColumn(ref dgvPosition, "PD_OtherAllowance", UpdateUI.GetString("phucapkhac"), "R", 110, true, true);
            UISetting.AddColumn(ref dgvPosition, "PD_TotalSalary", UpdateUI.GetString("luongthucnhan"), "R", 110, true, true);

        }
        private void LoadPositionDetail(int EmPloyeeID)
        {
            try
            {
                PositionDetailClient wcfWPositionDe = Service.PositionDetail();
                DataSet ds = wcfWPositionDe.PositionDetail_GetWithEmployee(EmPloyeeID);
                dgvPosition.Rows.Clear();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    dgvPosition.Rows.Insert(i, 1);
                    dgvPosition.Rows[i].Cells["PD_ID"].Value = ds.Tables[0].Rows[i]["PD_ID"].ToString();
                    dgvPosition.Rows[i].Cells["PD_PositionID"].Value = ds.Tables[0].Rows[i]["PD_PositionID"].ToString();
                    dgvPosition.Rows[i].Cells["PD_EmployeeID"].Value = ds.Tables[0].Rows[i]["PD_EmployeeID"].ToString();
                    dgvPosition.Rows[i].Cells["PD_DepartmentID"].Value = ds.Tables[0].Rows[i]["PD_DepartmentID"].ToString();
                    dgvPosition.Rows[i].Cells["PD_IsActive"].Value = ds.Tables[0].Rows[i]["PD_IsActive"].ToString();
                    dgvPosition.Rows[i].Cells["DepartmentName"].Value = ds.Tables[0].Rows[i]["DepartmentName"].ToString();
                    dgvPosition.Rows[i].Cells["PositionName"].Value = ds.Tables[0].Rows[i]["PositionName"].ToString();

                    if (ds.Tables[0].Rows[i]["PD_BeginDate"] != DBNull.Value)
                        dgvPosition.Rows[i].Cells["PD_BeginDate"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["PD_BeginDate"]).ToString("MM/yyyy");
                    else
                        dgvPosition.Rows[i].Cells["PD_BeginDate"].Value = "";
                    if (ds.Tables[0].Rows[i]["PD_EndDate"] != DBNull.Value)
                        dgvPosition.Rows[i].Cells["PD_EndDate"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["PD_EndDate"]).ToString("MM/yyyy");
                    else
                        dgvPosition.Rows[i].Cells["PD_EndDate"].Value = "";

                    if (ds.Tables[0].Rows[i]["PD_BasicFactor"] != DBNull.Value)
                        dgvPosition.Rows[i].Cells["PD_BasicFactor"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_BasicFactor"]).ToString(UIParamater.Cham3So);
                    else
                        dgvPosition.Rows[i].Cells["PD_BasicFactor"].Value = 0;

                    if (ds.Tables[0].Rows[i]["PD_PositionFactor"] != DBNull.Value)
                        dgvPosition.Rows[i].Cells["PD_PositionFactor"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_PositionFactor"]).ToString(UIParamater.Cham3So);
                    else
                        dgvPosition.Rows[i].Cells["PD_PositionFactor"].Value = 0;

                    if (ds.Tables[0].Rows[i]["PD_BasicSalary"] != DBNull.Value)
                        dgvPosition.Rows[i].Cells["PD_BasicSalary"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_BasicSalary"]).ToString("#,##0");
                    else
                        dgvPosition.Rows[i].Cells["PD_BasicSalary"].Value = 0;
                    if (ds.Tables[0].Rows[i]["PD_PositionAllowance"] != DBNull.Value)
                        dgvPosition.Rows[i].Cells["PD_PositionAllowance"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_PositionAllowance"]).ToString("#,##0");
                    else
                        dgvPosition.Rows[i].Cells["PD_PositionAllowance"].Value = 0;
                    if (ds.Tables[0].Rows[i]["PD_LunchAllowance"] != DBNull.Value)
                        dgvPosition.Rows[i].Cells["PD_LunchAllowance"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_LunchAllowance"]).ToString("#,##0");
                    else
                        dgvPosition.Rows[i].Cells["PD_LunchAllowance"].Value = 0;
                    if (ds.Tables[0].Rows[i]["PD_TelephoneAllowance"] != DBNull.Value)
                        dgvPosition.Rows[i].Cells["PD_TelephoneAllowance"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_TelephoneAllowance"]).ToString("#,##0");
                    else
                        dgvPosition.Rows[i].Cells["PD_TelephoneAllowance"].Value = 0;
                    if (ds.Tables[0].Rows[i]["PD_OtherAllowance"] != DBNull.Value)
                        dgvPosition.Rows[i].Cells["PD_OtherAllowance"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_OtherAllowance"]).ToString("#,##0");
                    else
                        dgvPosition.Rows[i].Cells["PD_OtherAllowance"].Value = 0;
                    if (ds.Tables[0].Rows[i]["PD_TotalSalary"] != DBNull.Value)
                        dgvPosition.Rows[i].Cells["PD_TotalSalary"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_TotalSalary"]).ToString("#,##0");
                    else
                        dgvPosition.Rows[i].Cells["PD_TotalSalary"].Value = 0;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }
        }

        private void AddColumnPremium()
        {
            UISetting.AddColumn(ref dgvPremium, "Premium_ID", "Mã chính", "", 1, false, true);
            //UISetting.AddColumn(ref dgvPremium, "RowNumber", UpdateUI.GetString("stt"), "C", 40, true, true);
            UISetting.AddColumn(ref dgvPremium, "Premium_FromDate", UpdateUI.GetString("tuthangnam"), "C", 100, true, true);
            UISetting.AddColumn(ref dgvPremium, "Premium_ToDate", UpdateUI.GetString("denthangnam"), "C", 110, true, true);
            UISetting.AddColumn(ref dgvPremium, "Premium_WorkUnit", UpdateUI.GetString("donvilamviec"), "", 150, true, true);
            UISetting.AddColumn(ref dgvPremium, "Premium_Job", UpdateUI.GetString("nghenghiep"), "", 130, true, true);
            UISetting.AddColumn(ref dgvPremium, "Premium_Salary", UpdateUI.GetString("tienluong"), "R", 120, true, true);
            UISetting.AddColumn(ref dgvPremium, "Premium_BasicFactor", "HSL", "R", 60, true, true);
            UISetting.AddColumn(ref dgvPremium, "Premium_PositionFactor", "HS Cvụ", "R", 100, true, true);
            UISetting.AddColumn(ref dgvPremium, "Premium_SeniorityFactor", "HS TNNghề", "R", 120, true, true);
            UISetting.AddColumn(ref dgvPremium, "Premium_OverSeniorityFactor", "HS TNVK", "R", 180, false, true);
            UISetting.AddColumn(ref dgvPremium, "Premium_AreaFactor", "HS KV", "R", 100, false, true);
            UISetting.AddColumn(ref dgvPremium, "Premium_MonthNo", UpdateUI.GetString("tongsothang"), "R", 120, true, true);
            UISetting.AddColumn(ref dgvPremium, "Premium_Description", UpdateUI.GetString("ghichu"), "", 100, false, true);
            UISetting.AddColumn(ref dgvPremium, "Detail_ID", "Detail_ID", "", 30, false, true);
        }
        private void LoadPremium()
        {
            //try
            //{
            //    DataTable dt = new DataTable();
            //    PremiumClient _wcfPremium = Service.Premium();
            //    dt = _wcfPremium.Premium_GetBySIBookNo(_employeeInfo.SIBookNo).Tables[0];
            //    dgvPremium.Rows.Clear();
            //    if (dt != null)
            //    {
            //        for (int i = 0; i < dt.Rows.Count; i++)
            //        {
            //            dgvPremium.Rows.Insert(i, 1);
            //            dgvPremium.Rows[i].Cells["Premium_ID"].Value = dt.Rows[i]["Premium_ID"].ToString();
            //            //dgvPremium.Rows[i].Cells["RowNumber"].Value = dt.Rows[i]["RowNumber"].ToString();
            //            dgvPremium.Rows[i].Cells["Premium_FromDate"].Value = Convert.ToDateTime(dt.Rows[i]["Premium_FromDate"]).ToString("MM/yyyy");
            //            dgvPremium.Rows[i].Cells["Premium_ToDate"].Value = Convert.ToDateTime(dt.Rows[i]["Premium_ToDate"]).ToString("MM/yyyy");
            //            dgvPremium.Rows[i].Cells["Premium_WorkUnit"].Value = dt.Rows[i]["Premium_WorkUnit"].ToString();
            //            dgvPremium.Rows[i].Cells["Premium_Job"].Value = dt.Rows[i]["Premium_Job"].ToString();
            //            dgvPremium.Rows[i].Cells["Premium_Salary"].Value = Convert.ToDecimal(dt.Rows[i]["Premium_Salary"]).ToString("#,##0");
            //            dgvPremium.Rows[i].Cells["Premium_BasicFactor"].Value = Convert.ToDecimal(dt.Rows[i]["Premium_BasicFactor"]).ToString("#0.0##");
            //            dgvPremium.Rows[i].Cells["Premium_PositionFactor"].Value = Convert.ToDecimal(dt.Rows[i]["Premium_PositionFactor"]).ToString("#0.0##");
            //            dgvPremium.Rows[i].Cells["Premium_SeniorityFactor"].Value = Convert.ToDecimal(dt.Rows[i]["Premium_SeniorityFactor"]).ToString("#0.0##");
            //            dgvPremium.Rows[i].Cells["Premium_OverSeniorityFactor"].Value = Convert.ToDecimal(dt.Rows[i]["Premium_OverSeniorityFactor"]).ToString("#0.0##");
            //            dgvPremium.Rows[i].Cells["Premium_AreaFactor"].Value = Convert.ToDecimal(dt.Rows[i]["Premium_AreaFactor"]).ToString("#0.0##");
            //            dgvPremium.Rows[i].Cells["Premium_MonthNo"].Value = dt.Rows[i]["Premium_MonthNo"].ToString();
            //            dgvPremium.Rows[i].Cells["Premium_Description"].Value = dt.Rows[i]["Premium_Description"].ToString();
            //            dgvPremium.Rows[i].Cells["Detail_ID"].Value = dt.Rows[i]["Detail_ID"].ToString();
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            //}
        }

        private void AddColumnAward()
        {
            UISetting.AddColumn(ref dgvRewardDiscipline, "Award_ID", "Mã chính", "C", 1, false, true);
            UISetting.AddColumn(ref dgvRewardDiscipline, "Award_EmployeeID", "Mã Nhân viên", "C", 10, false, true);
            UISetting.AddColumn(ref dgvRewardDiscipline, "Award_No", "Số QĐ", "C", 100, true, true);
            UISetting.AddColumn(ref dgvRewardDiscipline, "Award_Date", UpdateUI.GetString("ngay"), "C", 120, true, true);
            UISetting.AddColumn(ref dgvRewardDiscipline, "Award_TypeName", UpdateUI.GetString("loai"), "C", 100, true, true);
            UISetting.AddColumn(ref dgvRewardDiscipline, "Award_Amount", UpdateUI.GetString("sotien"), "C", 100, true, true);
        }
        private void LoadAward(int EmPloyeeID)
        {
            AwardClient _wcfAward = Service.Award();
            DataSet ds = _wcfAward.Award_GetAllByEmployee(EmPloyeeID);
            dgvRewardDiscipline.Rows.Clear();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dgvRewardDiscipline.Rows.Insert(i, 1);
                dgvRewardDiscipline.Rows[i].Cells["Award_ID"].Value = ds.Tables[0].Rows[i]["Award_ID"].ToString();
                dgvRewardDiscipline.Rows[i].Cells["Award_No"].Value = ds.Tables[0].Rows[i]["Award_No"].ToString();
                dgvRewardDiscipline.Rows[i].Cells["Award_EmployeeID"].Value = ds.Tables[0].Rows[i]["Award_EmployeeID"].ToString();
                if (ds.Tables[0].Rows[i]["Award_Date"] != DBNull.Value)
                    dgvRewardDiscipline.Rows[i].Cells["Award_Date"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["Award_Date"]).ToString("dd/MM/yyyy");
                else
                    dgvRewardDiscipline.Rows[i].Cells["Award_Date"].Value = "";
                dgvRewardDiscipline.Rows[i].Cells["Award_Amount"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["Award_Amount"]).ToString("#,##0");
                dgvRewardDiscipline.Rows[i].Cells["Award_TypeName"].Value = ds.Tables[0].Rows[i]["Award_TypeName"].ToString();
            }
        }

        private void AddColumnComment()
        {
            UISetting.AddColumn(ref dgvComment, "Comment_ID", "Mã chính", "", 1, false, true);
            UISetting.AddColumn(ref dgvComment, "Comment_EmployeeID", "Mã Nhân viên", "", 10, false, true);
            UISetting.AddColumn(ref dgvComment, "Comment_Kind", UpdateUI.GetString("hinhthuc"), "", 140, true, true);
            UISetting.AddColumn(ref dgvComment, "comment_Date", UpdateUI.GetString("ngay"), "C", 110, true, true);
            UISetting.AddColumn(ref dgvComment, "Comment_Speciality", UpdateUI.GetString("chuyennganh"), "", 150, true, true);
            UISetting.AddColumn(ref dgvComment, "Comment_Morality", UpdateUI.GetString("daoduc"), "", 120, true, true);
            UISetting.AddColumn(ref dgvComment, "Comment_Discipline", UpdateUI.GetString("kyluat"), "", 120, true, true);
            UISetting.AddColumn(ref dgvComment, "Comment_Accept", UpdateUI.GetString("chapnhan"), "", 100, true, true);
        }
        private void LoadComment(int EmPloyeeID)
        {
            try
            {
                CommentClient wcfComment = Service.Comment();
                DataSet ds = wcfComment.Comment_GetWithEmployee(EmPloyeeID);
                dgvComment.Rows.Clear();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    dgvComment.Rows.Insert(i, 1);
                    dgvComment.Rows[i].Cells["Comment_ID"].Value = ds.Tables[0].Rows[i]["Comment_ID"].ToString();
                    dgvComment.Rows[i].Cells["Comment_EmployeeID"].Value = ds.Tables[0].Rows[i]["Comment_EmployeeID"].ToString();
                    dgvComment.Rows[i].Cells["Comment_Kind"].Value = ds.Tables[0].Rows[i]["Comment_Kind"].ToString();
                    if (ds.Tables[0].Rows[i]["comment_Date"] != DBNull.Value)
                        dgvComment.Rows[i].Cells["comment_Date"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["comment_Date"]).ToString("dd/MM/yyyy");
                    else
                        dgvComment.Rows[i].Cells["comment_Date"].Value = "";
                    dgvComment.Rows[i].Cells["Comment_Speciality"].Value = ds.Tables[0].Rows[i]["Comment_Speciality"].ToString();
                    dgvComment.Rows[i].Cells["Comment_Morality"].Value = ds.Tables[0].Rows[i]["Comment_Morality"].ToString();
                    dgvComment.Rows[i].Cells["Comment_Discipline"].Value = ds.Tables[0].Rows[i]["Comment_Discipline"].ToString();
                    dgvComment.Rows[i].Cells["Comment_Accept"].Value = ds.Tables[0].Rows[i]["Comment_Accept"].ToString();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }
        }

        private void AddColumnSafetyDevice()
        {
            UISetting.AddColumn(ref dgvSafetyDevice, "SafetyDevice_ID", "Mã chính", "", 1, false, true);
            UISetting.AddColumn(ref dgvSafetyDevice, "SafetyDevice_EmployeeID", "Mã Nhân viên", "", 10, false, true);
            UISetting.AddColumn(ref dgvSafetyDevice, "SafetyDevice_Name", UpdateUI.GetString("tenthietbi"), "", 180, true, true);
            UISetting.AddColumn(ref dgvSafetyDevice, "SafetyDevice_Date", UpdateUI.GetString("ngaygiao"), "C", 110, true, true);
            UISetting.AddColumn(ref dgvSafetyDevice, "SafetyDevice_Type", UpdateUI.GetString("loaithietbi"), "", 150, false, true);
            UISetting.AddColumn(ref dgvSafetyDevice, "SafetyDevice_No", UpdateUI.GetString("soluong"), "", 130, true, true);
            UISetting.AddColumn(ref dgvSafetyDevice, "SafetyDevice_Status", UpdateUI.GetString("trangthai"), "", 250, true, true);
        }
        private void LoadSafetyDevice(int EmPloyeeID)
        {
            try
            {
                SafetyDeviceClient wcfSafetyDevice = Service.SafetyDevice();
                DataSet ds = wcfSafetyDevice.SafetyDevice_GetWithEmployee(EmPloyeeID);
                dgvSafetyDevice.Rows.Clear();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    dgvSafetyDevice.Rows.Insert(i, 1);
                    dgvSafetyDevice.Rows[i].Cells["SafetyDevice_ID"].Value = ds.Tables[0].Rows[i]["SafetyDevice_ID"].ToString();
                    dgvSafetyDevice.Rows[i].Cells["SafetyDevice_EmployeeID"].Value = ds.Tables[0].Rows[i]["SafetyDevice_EmployeeID"].ToString();
                    dgvSafetyDevice.Rows[i].Cells["SafetyDevice_Name"].Value = ds.Tables[0].Rows[i]["SafetyDevice_Name"].ToString();
                    if (ds.Tables[0].Rows[i]["SafetyDevice_Date"] != DBNull.Value)
                        dgvSafetyDevice.Rows[i].Cells["SafetyDevice_Date"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["SafetyDevice_Date"]).ToString("dd/MM/yyyy");
                    else
                        dgvSafetyDevice.Rows[i].Cells["SafetyDevice_Date"].Value = "";
                    dgvSafetyDevice.Rows[i].Cells["SafetyDevice_Type"].Value = ds.Tables[0].Rows[i]["SafetyDevice_Type"].ToString();
                    dgvSafetyDevice.Rows[i].Cells["SafetyDevice_No"].Value = ds.Tables[0].Rows[i]["SafetyDevice_No"].ToString();
                    dgvSafetyDevice.Rows[i].Cells["SafetyDevice_Status"].Value = ds.Tables[0].Rows[i]["SafetyDevice_Status"].ToString();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }
        }

        private void AddColumnVisa()
        {
            UISetting.AddColumn(ref dgvVisa, "Visa_ID", "Mã chính", "", 1, false, true);
            UISetting.AddColumn(ref dgvVisa, "Visa_EmployeeID", "Mã Nhân viên", "", 10, false, true);
            UISetting.AddColumn(ref dgvVisa, "Visa_No", UpdateUI.GetString("sovisa"), "", 150, true, true);
            UISetting.AddColumn(ref dgvVisa, "Visa_IssueDate", UpdateUI.GetString("ngaycap"), "C", 110, true, true);
            UISetting.AddColumn(ref dgvVisa, "Visa_ExpireDate", UpdateUI.GetString("ngayhethan"), "C", 110, true, true);
            UISetting.AddColumn(ref dgvVisa, "Visa_AuthorIssue", UpdateUI.GetString("noicap"), "", 160, true, true);
        }
        private void LoadVisa(int EmployeeID)
        {
            try
            {
                VisaClient wcfVisa = Service.Visa();
                DataSet ds = wcfVisa.Visa_GetWithEmployee(EmployeeID);
                dgvVisa.Rows.Clear();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    dgvVisa.Rows.Insert(i, 1);
                    dgvVisa.Rows[i].Cells["Visa_ID"].Value = ds.Tables[0].Rows[i]["Visa_ID"].ToString();
                    dgvVisa.Rows[i].Cells["Visa_EmployeeID"].Value = ds.Tables[0].Rows[i]["Visa_EmployeeID"].ToString();
                    dgvVisa.Rows[i].Cells["Visa_No"].Value = ds.Tables[0].Rows[i]["Visa_No"].ToString();
                    if (ds.Tables[0].Rows[i]["Visa_IssueDate"] != DBNull.Value)
                        dgvVisa.Rows[i].Cells["Visa_IssueDate"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["Visa_IssueDate"]).ToString("dd/MM/yyyy");
                    else
                        dgvVisa.Rows[i].Cells["Visa_IssueDate"].Value = "";
                    if (ds.Tables[0].Rows[i]["Visa_ExpireDate"] != DBNull.Value)
                        dgvVisa.Rows[i].Cells["Visa_ExpireDate"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["Visa_ExpireDate"]).ToString("dd/MM/yyyy");
                    else
                        dgvVisa.Rows[i].Cells["Visa_ExpireDate"].Value = "";
                    dgvVisa.Rows[i].Cells["Visa_AuthorIssue"].Value = ds.Tables[0].Rows[i]["Visa_AuthorIssue"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }
        }
        private void AddColumnLeaveRecord()
        {
            UISetting.AddColumn(ref dgvLeaveRecord, "LeaveRecord_ID", "Mã chính", "", 1, false, true);
            UISetting.AddColumn(ref dgvLeaveRecord, "LeaveRecord_EmployeeID", "Mã Nhân viên", "", 10, false, true);
            UISetting.AddColumn(ref dgvLeaveRecord, "LeaveRecord_FromDate", UpdateUI.GetString("tungay"), "C", 95, true, true);
            UISetting.AddColumn(ref dgvLeaveRecord, "LeaveRecord_ToDate", UpdateUI.GetString("denngay"), "C", 95, true, true);
            UISetting.AddColumn(ref dgvLeaveRecord, "LeaveRecord_ALDays", UpdateUI.GetString("ngayAL"), "R", 130, true, true);
            UISetting.AddColumn(ref dgvLeaveRecord, "LeaveRecord_CODays", UpdateUI.GetString("ngayCO"), "R", 130, true, true);
            UISetting.AddColumn(ref dgvLeaveRecord, "LeaveRecord_ALBefore", UpdateUI.GetString("ngayALB"), "R", 160, true, true);
            UISetting.AddColumn(ref dgvLeaveRecord, "LeaveRecord_COBefore", UpdateUI.GetString("ngayCOB"), "R", 145, true, true);
        }
        private void LoadLeaveRecord(int EmployeeID)
        {
            try
            {
                LeaveRecordClient wcfLeaveRecord = Service.LeaveRecord();
                DataSet ds = wcfLeaveRecord.LeaveRecord_GetWithEmployee(EmployeeID);

                dgvLeaveRecord.Rows.Clear();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    dgvLeaveRecord.Rows.Insert(i, 1);
                    dgvLeaveRecord.Rows[i].Cells["LeaveRecord_ID"].Value = ds.Tables[0].Rows[i]["LeaveRecord_ID"].ToString();
                    dgvLeaveRecord.Rows[i].Cells["LeaveRecord_EmployeeID"].Value = ds.Tables[0].Rows[i]["LeaveRecord_EmployeeID"].ToString();
                    if (ds.Tables[0].Rows[i]["LeaveRecord_FromDate"] != DBNull.Value)
                        dgvLeaveRecord.Rows[i].Cells["LeaveRecord_FromDate"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["LeaveRecord_FromDate"]).ToString("dd/MM/yyyy");
                    else
                        dgvLeaveRecord.Rows[i].Cells["LeaveRecord_FromDate"].Value = "";
                    if (ds.Tables[0].Rows[i]["LeaveRecord_ToDate"] != DBNull.Value)
                        dgvLeaveRecord.Rows[i].Cells["LeaveRecord_ToDate"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["LeaveRecord_ToDate"]).ToString("dd/MM/yyyy");
                    else
                        dgvLeaveRecord.Rows[i].Cells["LeaveRecord_ToDate"].Value = "";
                    dgvLeaveRecord.Rows[i].Cells["LeaveRecord_ALDays"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LeaveRecord_ALDays"]).ToString("#,##0.0");
                    dgvLeaveRecord.Rows[i].Cells["LeaveRecord_CODays"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LeaveRecord_CODays"]).ToString("#,##0.0");
                    dgvLeaveRecord.Rows[i].Cells["LeaveRecord_ALBefore"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LeaveRecord_ALBefore"]).ToString("#,##0.0");
                    dgvLeaveRecord.Rows[i].Cells["LeaveRecord_COBefore"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LeaveRecord_COBefore"]).ToString("#,##0.0");
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(UpdateUI.GetString("loi") + ":\n" + ex.Message + "\n" + UpdateUI.GetString("ghiloi"));
            }

        }
        private void dgvLeaveRecord_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnLeaveRecord_Edit_Click(null, null);
        }
        private void btnLeaveRecord_New_Click(object sender, EventArgs e)
        {
            if (!_listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_employeeInfo.ID == 0)
            {

                MessageBox.Show("Bạn cần phải lưu thông tin nhân viên này trước!", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                Form f = new frmLeaveRecord(0, _employeeInfo.ID, _listRole);
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    LoadLeaveRecord(_employeeID);
                }
            }
        }
        private void btnLeaveRecord_Edit_Click(object sender, EventArgs e)
        {
            if (dgvLeaveRecord.SelectedRows.Count > 0)
            {
                if (_listRole.Update || _listRole.View)
                {
                    Form f = new frmLeaveRecord(Convert.ToInt32(dgvLeaveRecord.CurrentRow.Cells["LeaveRecord_ID"].Value), _employeeID, _listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        LoadLeaveRecord(_employeeID);
                    }
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void btnLeaveRecord_Del_Click(object sender, EventArgs e)
        {
            if (dgvLeaveRecord.SelectedRows.Count > 0)
            {
                if (!_listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxoa"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    LeaveRecordClient _wcfLeaveRecord = Service.LeaveRecord();
                    if (_wcfLeaveRecord.LeaveRecord_Delete(Convert.ToInt32(dgvLeaveRecord.CurrentRow.Cells["LeaveRecord_ID"].Value)))
                    {
                        Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                        LoadLeaveRecord(_employeeID);
                    }
                    else
                    {
                        MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
        private void btnNewFamily_Click(object sender, EventArgs e)
        {
            if (!_listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_employeeInfo.ID == 0)
            {
                MessageBox.Show("Bạn cần phải lưu thông tin nhân viên này trước!", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                Form f = new frmFamilyInfo(0, _employeeInfo.ID, _listRole);
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    LoadFamily(_employeeID);
                }
            }
        }
        private void btnEditFamily_Click(object sender, EventArgs e)
        {
            if (dgvFamily.SelectedRows.Count > 0)
            {
                if (_listRole.Update || _listRole.View)
                {

                    Form f = new frmFamilyInfo(Convert.ToInt32(dgvFamily.CurrentRow.Cells["Family_ID"].Value), _employeeID, _listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        LoadFamily(_employeeID);
                    }
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void btnDelFamily_Click(object sender, EventArgs e)
        {
            if (dgvFamily.SelectedRows.Count > 0)
            {
                if (!_listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxoa"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    FamilyClient wcfFamily = Service.Family();
                    if (wcfFamily.Family_Delete(Convert.ToInt32(dgvFamily.CurrentRow.Cells["Family_ID"].Value)))
                    {
                        Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                        LoadFamily(_employeeID);
                    }
                    else
                    {
                        MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
        private void btnNewCertificate_Click(object sender, EventArgs e)
        {
            if (!_listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_employeeInfo.ID == 0)
            {

                MessageBox.Show("Bạn cần phải lưu thông tin nhân viên này trước!", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                Form f = new frmCertificateInfo(0, _employeeInfo.ID, _listRole);
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    LoadCertificate(_employeeID);
                }
            }
        }
        private void btnEditCertificate_Click(object sender, EventArgs e)
        {
            if (dgvCertificate.SelectedRows.Count > 0)
            {
                if (_listRole.Update || _listRole.View)
                {
                    Form f = new frmCertificateInfo(Convert.ToInt32(dgvCertificate.CurrentRow.Cells["Certificate_ID"].Value), _employeeID, _listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        LoadCertificate(_employeeID);
                    }
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void btnDelCertificate_Click(object sender, EventArgs e)
        {
            if (dgvCertificate.SelectedRows.Count > 0)
            {
                if (!_listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxoa"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    CertificateClient wcfCertificate = Service.Certificate();
                    if (wcfCertificate.Certificate_Delete(Convert.ToInt32(dgvCertificate.CurrentRow.Cells["Certificate_ID"].Value)))
                    {
                        Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                        LoadCertificate(_employeeID);
                    }
                    else
                    {
                        MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
        private void btnNewWBackground_Click(object sender, EventArgs e)
        {
            if (!_listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_employeeInfo.ID == 0)
            {
                MessageBox.Show("Bạn cần phải lưu thông tin nhân viên này trước!", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                Form f = new frmWorkingBachgroundInfo(0, _employeeInfo.ID, _listRole);
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    LoadWbackground(_employeeID);
                }
            }
        }
        private void btnEditWBackground_Click(object sender, EventArgs e)
        {
            if (dgvBackGround.SelectedRows.Count > 0)
            {
                if (_listRole.Update || _listRole.View)
                {
                    Form f = new frmWorkingBachgroundInfo(Convert.ToInt32(dgvBackGround.CurrentRow.Cells["WB_ID"].Value), _employeeID, _listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        LoadWbackground(_employeeID);
                    }
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void btnDelWBackground_Click(object sender, EventArgs e)
        {
            if (dgvBackGround.SelectedRows.Count > 0)
            {
                if (!_listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxoa"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    WorkingBackground_Controller wcfWBackground = WorkingBackground_Controller.Instance();
                    
                    if (wcfWBackground.WorkingBackground_Delete(Convert.ToInt32(dgvBackGround.CurrentRow.Cells["WB_ID"].Value)))
                    {
                        Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                        LoadWbackground(_employeeID);
                    }
                    else
                    {
                        MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
        private void btnNewPositionDetail_Click(object sender, EventArgs e)
        {

            if (_employeeInfo.ID == 0)
            {
                MessageBox.Show("Bạn cần phải lưu thông tin nhân viên này trước!", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                frmPositionDetailsInfo f = new frmPositionDetailsInfo(0, _employeeInfo.ID, _listRole);
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    LoadPositionDetail(_employeeInfo.ID);
                    _dlgResult = DialogResult.OK;
                    if (_employeeInfo.Code.Trim().Length == 0)
                    {
                        txtEmployee_Code.Text = f.EmployeeCode;
                        _wcfEployee.Employee_UpdateEmployeeCode(_employeeInfo.ID, txtEmployee_Code.Text);
                    }
                }
            }
        }
        private void btnEditPositionDetail_Click(object sender, EventArgs e)
        {
            if (dgvPosition.SelectedRows.Count > 0)
            {
                if (_listRole.Update || _listRole.View)
                {
                    Form f = new frmPositionDetailsInfo(Convert.ToInt32(dgvPosition.CurrentRow.Cells["PD_ID"].Value), _employeeID, _listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {

                        LoadPositionDetail(_employeeID);
                    }
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void btnDelPositionDetail_Click(object sender, EventArgs e)
        {
            if (dgvPosition.RowCount == 1 || Convert.ToBoolean(dgvPosition.CurrentRow.Cells["PD_IsActive"].Value))
            {
                MessageBox.Show("Bạn không thể xóa thông tin lương/phòng ban mặc định, bạn có thể cập nhật thông tin hoặc tạo thêm bản ghi khác", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (dgvPosition.SelectedRows.Count > 0)
            {
                if (!_listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxoa"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    PositionDetailClient wcfWPositionDe = Service.PositionDetail();                    
                    if (wcfWPositionDe.PositionDetail_Delete(Convert.ToInt32(dgvPosition.CurrentRow.Cells["PD_ID"].Value)))
                    {
                        Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                        LoadPositionDetail(_employeeID);
                    }
                    else
                    {
                        MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
        private void btnNewComment_Click(object sender, EventArgs e)
        {
            if (!_listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_employeeInfo.ID == 0)
            {
                MessageBox.Show("Bạn cần phải lưu thông tin nhân viên này trước!", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                Form f = new frmCommentInfo(0, _employeeInfo.ID, _listRole);
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    LoadComment(_employeeID);
                }
            }
        }
        private void btnEditComment_Click(object sender, EventArgs e)
        {
            if (dgvComment.SelectedRows.Count > 0)
            {
                if (_listRole.Update || _listRole.View)
                {
                    Form f = new frmCommentInfo(Convert.ToInt32(dgvComment.CurrentRow.Cells["Comment_ID"].Value), _employeeID, _listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        LoadComment(_employeeID);
                    }
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void btnDelComment_Click(object sender, EventArgs e)
        {
            if (dgvComment.SelectedRows.Count > 0)
            {
                if (!_listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxoa"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    CommentClient wcfComment = Service.Comment();
                    if (wcfComment.Comment_Delete(Convert.ToInt32(dgvComment.CurrentRow.Cells["Comment_ID"].Value)))
                    {
                        Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                        LoadComment(_employeeID);
                    }
                    else
                    {
                        MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
        private void btnNewReward_Click(object sender, EventArgs e)
        {
            if (!_listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_employeeInfo.ID == 0)
            {
                MessageBox.Show("Bạn cần phải lưu thông tin nhân viên này trước!", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                Form f = new frmAwardInfo(0, _employeeID);
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    LoadAward(_employeeID);
                }
            }
        }
        private void btnEditReward_Click(object sender, EventArgs e)
        {
            if (dgvRewardDiscipline.SelectedRows.Count > 0)
            {
                if (_listRole.Update || _listRole.View)
                {
                    int _AwardID = Convert.ToInt32(dgvRewardDiscipline.CurrentRow.Cells["Award_ID"].Value);
                    Form f = new frmAwardInfo(_AwardID, _employeeID);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        LoadAward(_employeeID);
                    }
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void btnDelReward_Click(object sender, EventArgs e)
        {
            if (dgvRewardDiscipline.SelectedRows.Count > 0)
            {
                if (!_listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                int _AwardID = Convert.ToInt32(dgvRewardDiscipline.CurrentRow.Cells["Award_ID"].Value);
                if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    AwardClient _wcfAward = Service.Award();
                    if (_wcfAward.Award_Delete(_AwardID))
                    {
                        Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                        LoadAward(_employeeID);
                    }
                    else
                    {
                        MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
        private void dgvPosition_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnEditPositionDetail_Click(null, null);
        }
        private void dgvLabourContract_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnLabourContractEdit_Click(null, null);
        }
        private void dgvFamily_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnEditFamily_Click(null, null);
        }
        private void dgvCertificate_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnEditCertificate_Click(null, null);
        }
        private void dgvBackGround_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnEditWBackground_Click(null, null);
        }
        private void dgvRewardDiscipline_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnEditReward_Click(null, null);
        }
        private void dgvComment_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnEditComment_Click(null, null);
        }
        private void btnPremiumAdd_Click(object sender, EventArgs e)
        {
            if (!_listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_employeeInfo.ID == 0)
            {
                MessageBox.Show("Bạn cần phải lưu thông tin nhân viên này trước!", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            {
                //Form f = new frmfrmEmployee_QTChucDanh_Edit(0, _employeeID, 0, _listRole);
                //if (f.ShowDialog(this) == DialogResult.OK)
                //{
                //    LoadPremium();
                //}
            }
        }
        private void btnPremiumEdit_Click(object sender, EventArgs e)
        {
            if (dgvPremium.SelectedRows.Count > 0)
            {
                int _DetailID = 0;

                if (_listRole.Update || _listRole.View)
                {
                    _DetailID = Convert.ToInt32(dgvPremium.SelectedRows[0].Cells["Detail_ID"].Value);
                    PremiumID = Convert.ToInt32(dgvPremium.SelectedRows[0].Cells["Premium_ID"].Value);
                    //Form f = new frmfrmEmployee_QTChucDanh_Edit(PremiumID, _employeeID, _DetailID, _listRole);
                    //if (f.ShowDialog(this) == DialogResult.OK)
                    //{
                    //    LoadPremium();
                    //}
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void btnPremiumDelete_Click(object sender, EventArgs e)
        {
            if (dgvPremium.SelectedRows.Count > 0)
            {
                if (!_listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxoa"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                PremiumID = Convert.ToInt32(dgvPremium.SelectedRows[0].Cells["Premium_ID"].Value);
                if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    PremiumClient _wcfPremium = Service.Premium();
                    if (_wcfPremium.Premium_Delete(PremiumID))
                    {
                        Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                        LoadPremium();
                    }
                    else
                    {
                        MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
        private void dgvPremium_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnPremiumEdit_Click(null, null);
        }
        private void btnImage_Click(object sender, EventArgs e)
        {
            OpenFileDialog Opd = new OpenFileDialog();
            Opd.Filter = "Image files(*.jpg)|*.jpg|(*.bmp)|*.bmp|(*.gif)|*.gif|(*.png)|*.png|AllFile(*.*)|*.*";
            if (Opd.ShowDialog() == DialogResult.OK)
            {
                picEmployee.ImageLocation = Opd.FileName;
                picEmployee.SizeMode = PictureBoxSizeMode.Zoom;
            }
        }
        private void btnNewVisa_Click(object sender, EventArgs e)
        {
            if (!_listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_employeeInfo.ID == 0)
            {
                MessageBox.Show("Bạn cần phải lưu thông tin nhân viên này trước!", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                Form f = new frmVisaInfo(0, _employeeInfo.ID, _listRole);
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    LoadVisa(_employeeID);
                }
            }
        }
        private void btnEditVisa_Click(object sender, EventArgs e)
        {
            if (dgvVisa.SelectedRows.Count > 0)
            {
                if (_listRole.Update || _listRole.View)
                {
                    Form f = new frmVisaInfo(Convert.ToInt32(dgvVisa.CurrentRow.Cells["Visa_ID"].Value), _employeeID, _listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        LoadVisa(_employeeID);
                    }
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void btnDelVisa_Click(object sender, EventArgs e)
        {
            if (dgvVisa.SelectedRows.Count > 0)
            {
                if (!_listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxoa"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    VisaClient wcfVisa = Service.Visa();
                    if (wcfVisa.Visa_Delete(Convert.ToInt32(dgvVisa.CurrentRow.Cells["Visa_ID"].Value)))
                    {
                        Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                        LoadVisa(_employeeID);
                    }
                    else
                    {
                        MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
        //private void btnCreateUser_Click(object sender, EventArgs e)
        //{
        //    if (_employeeID > 0)
        //    {
        //        string _fullname = txtEmployee_LastName.Text + " " + txtEmployee_FisrtName.Text;
        //        string _address = txtEmployee_Address.Text;
        //        string _phone = txtEmployee_Phone.Text;
        //        int _departmentid = 0;
        //        for (int i = 0; i < dgvPosition.Rows.Count; i++)
        //        {
        //            if (Convert.ToBoolean(dgvPosition.Rows[i].Cells["PD_IsActive"].Value))
        //                _departmentid = Convert.ToInt32(dgvPosition.Rows[i].Cells["PD_DepartmentID"].Value);
        //        }

        //        frmUserInfo f = new frmUserInfo("", new string[] { _fullname, _address, _phone, _departmentid.ToString() });
        //        if (f.ShowDialog(this) == DialogResult.OK)
        //        {
        //            txtUserName.Text = " | " + UpdateUI.GetString("tendangnhap") + ": " + f.UserName;
        //            btnCreateUser.Visible = false;
        //            toolStripSeparator19.Visible = false;
        //            if (_wcfEployee.Employee_UpdateUserName(_employeeID, f.UserName))
        //            {
        //                Program.taskbarNotifier.Show(UpdateUI.GetString("thongbao"), UpdateUI.GetString("themmoithanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
        //                _dlgResult = DialogResult.OK;
        //            }
        //        }
        //    }
        //}
        private void btnNewSafetyDevice_Click(object sender, EventArgs e)
        {
            if (!_listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_employeeInfo.ID == 0)
            {
                MessageBox.Show("Bạn cần phải lưu thông tin nhân viên này trước!", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                Form f = new frmSafetyDevice(0, _employeeInfo.ID, _listRole);
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    LoadSafetyDevice(_employeeID);
                }
            }
        }
        private void btnEditSafetyDevice_Click(object sender, EventArgs e)
        {
            if (dgvSafetyDevice.SelectedRows.Count > 0)
            {
                if (_listRole.Update || _listRole.View)
                {
                    Form f = new frmSafetyDevice(Convert.ToInt32(dgvSafetyDevice.CurrentRow.Cells["SafetyDevice_ID"].Value), _employeeID, _listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        LoadSafetyDevice(_employeeID);
                    }
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void btnDelSafetyDevice_Click(object sender, EventArgs e)
        {
            if (dgvSafetyDevice.SelectedRows.Count > 0)
            {
                if (!_listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxoa"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    SafetyDeviceClient wcfSafetyDevice = Service.SafetyDevice();
                    if (wcfSafetyDevice.SafetyDevice_Delete(Convert.ToInt32(dgvSafetyDevice.CurrentRow.Cells["SafetyDevice_ID"].Value)))
                    {
                        Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                        LoadSafetyDevice(_employeeID);
                    }
                    else
                    {
                        MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }

        private void txtEmployee_CardNo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar)) e.Handled = true;

        }
        private void dgvVisa_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnEditVisa_Click(null, null);
        }
        private void txtEmployee_LastName_TextChanged(object sender, EventArgs e)
        {
            ShowFullName();
            DataChanged(null, null);
        }
        private void txtEmployee_FisrtName_TextChanged(object sender, EventArgs e)
        {
            ShowFullName();
            DataChanged(null, null);

        }
        void ShowFullName()
        {
            lblFullName.Text = txtEmployee_LastName.Text.Trim().ToUpper() + " " + txtEmployee_FisrtName.Text.Trim().ToUpper();
        }

        #region Print Card


        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (_employeeID > 0)
            {
                frmPrintCard f = new frmPrintCard(_employeeID);
                f.ShowDialog(this);
            }
        }

        #endregion

        #region Index
        int _index = 0;
        DataTable dt = new DataTable();
        private int[] Nhanvien()
        {
            if (_employeeID > 0)
            {
                if (Program.isAdmin || Program.isViewAll)
                    dt = _wcfEployee.Employee_GetList2(_BranchID, _departmentID, _Type).Tables[0];
                else
                    dt = _wcfEployee.Employee_GetList2(Program.intBranchID, _departmentID, _Type).Tables[0];
                int n = dt.Rows.Count;
                int[] tracks = new int[n];
                for (int i = 0; i < n; i++)
                {
                    tracks[i] = Convert.ToInt32(dt.Rows[i]["Employee_ID"]);
                    if (_employeeID == tracks[i])
                        _index = i;
                }
                return tracks;
            }
            else
            {
                return null;
            }
        }

        private void btnFirst_Click(object sender, EventArgs e)
        {
            if (isChange)
            {
                if (MessageBox.Show("Bạn đã thay đổi dữ liệu.\nBạn có muốn lưu trước khi chuyển không?", UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    btnSave_Click(null, null);
                }
            }
            if (_employeeInfo.ID > 0)
            {
                _index = 0;
                _employeeID = EmployeeID[_index];
                _employeeInfo = _wcfEployee.Employee_GetInfo(_employeeID);
                Info2Form();
            }
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            if (isChange)
            {
                if (MessageBox.Show("Bạn đã thay đổi dữ liệu.\nBạn có muốn lưu trước khi chuyển không?", UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    btnSave_Click(null, null);
                }
            }
            if (_employeeInfo.ID > 0)
            {
                if (_index > 0)
                {
                    _index--;
                    _employeeID = EmployeeID[_index];
                    _employeeInfo = _wcfEployee.Employee_GetInfo(_employeeID);
                    Info2Form();
                }
            }
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (isChange)
            {
                if (MessageBox.Show("Bạn đã thay đổi dữ liệu.\nBạn có muốn lưu trước khi chuyển không?", UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    btnSave_Click(null, null);
                }
            }

            if (_employeeInfo.ID > 0)
            {

                if (_index < EmployeeID.Length - 1)
                {
                    _index++;
                    _employeeID = EmployeeID[_index];
                    _employeeInfo = _wcfEployee.Employee_GetInfo(_employeeID);
                    Info2Form();
                }
            }
        }

        private void btnLast_Click(object sender, EventArgs e)
        {
            if (isChange)
            {
                if (MessageBox.Show("Bạn đã thay đổi dữ liệu.\nBạn có muốn lưu trước khi chuyển không?", UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    btnSave_Click(null, null);
                }
            }
            if (_employeeInfo.ID > 0)
            {
                _index = EmployeeID.Length - 1;
                _employeeID = EmployeeID[_index];
                _employeeInfo = _wcfEployee.Employee_GetInfo(_employeeID);
                Info2Form();
            }
        }

        #endregion

        private void dgvSafetyDevice_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnEditSafetyDevice_Click(null, null);
        }

        private void btnInsertImage_Click(object sender, EventArgs e)
        {
            OpenFileDialog Opd = new OpenFileDialog();
            Opd.Filter = "Image files(*.jpg)|*.jpg|(*.bmp)|*.bmp|(*.gif)|*.gif|(*.png)|*.png|AllFile(*.*)|*.*";
            if (Opd.ShowDialog() == DialogResult.OK)
            {
                picEmployee.ImageLocation = Opd.FileName;
                picEmployee.SizeMode = PictureBoxSizeMode.Zoom;
            }
        }

        private void btnDelImage_Click(object sender, EventArgs e)
        {
            picEmployee.Image = null;
        }

        private void AddColumnEducation()
        {
            UISetting.AddColumn(ref dgvDaoTao, "Education_ID", "Mã chính", "", 1, false, true);
            UISetting.AddColumn(ref dgvDaoTao, "Education_EmployeeID", "Mã NV", "", 1, false, true);
            UISetting.AddColumn(ref dgvDaoTao, "Education_Name", UpdateUI.GetString("khoadaotao"), "", 130, true, true);
            UISetting.AddColumn(ref dgvDaoTao, "Education_Kind", UpdateUI.GetString("loaihinhdaotao"), "", 130, true, true);
            UISetting.AddColumn(ref dgvDaoTao, "Education_Major", UpdateUI.GetString("chuyennganh"), "", 130, true, true);
            UISetting.AddColumn(ref dgvDaoTao, "Education_Foreign", UpdateUI.GetString("nuocngoai"), "", 120, true, true);
            UISetting.AddColumn(ref dgvDaoTao, "Education_Place", UpdateUI.GetString("noidaotao"), "", 120, true, true);
            UISetting.AddColumn(ref dgvDaoTao, "Education_FromDate", UpdateUI.GetString("ngaybatdau"), "", 120, true, true);
            UISetting.AddColumn(ref dgvDaoTao, "Education_Time", UpdateUI.GetString("thoigian"), "", 120, true, true);
            UISetting.AddColumn(ref dgvDaoTao, "Education_DateIssue", UpdateUI.GetString("ngaycap"), "", 120, true, true);
            UISetting.AddColumn(ref dgvDaoTao, "Education_AuthorIssue", UpdateUI.GetString("noicap"), "", 120, true, true);
            UISetting.AddColumn(ref dgvDaoTao, "Education_Rank", UpdateUI.GetString("xeploai"), "", 120, true, true);
            UISetting.AddColumn(ref dgvDaoTao, "Education_Description", UpdateUI.GetString("ghichu"), "", 160, true, true);
        }

        private void LoadEducation(int _employeeID)
        {
            EducationClient wcfEducation = Service.Education();
            DataSet _ds = wcfEducation.Education_GetByEmployeeID(_employeeID);
            dgvDaoTao.Rows.Clear();
            for (int i = 0; i < _ds.Tables[0].Rows.Count; i++)
            {
                dgvDaoTao.Rows.Insert(i, 1);
                dgvDaoTao.Rows[i].Cells["Education_ID"].Value = _ds.Tables[0].Rows[i]["Education_ID"].ToString();
                dgvDaoTao.Rows[i].Cells["Education_EmployeeID"].Value = _ds.Tables[0].Rows[i]["Education_EmployeeID"].ToString();
                dgvDaoTao.Rows[i].Cells["Education_Name"].Value = _ds.Tables[0].Rows[i]["Education_Name"].ToString();
                dgvDaoTao.Rows[i].Cells["Education_Kind"].Value = _ds.Tables[0].Rows[i]["Education_Kind"].ToString();
                dgvDaoTao.Rows[i].Cells["Education_Major"].Value = _ds.Tables[0].Rows[i]["Education_Major"].ToString();
                if (Convert.ToBoolean(_ds.Tables[0].Rows[i]["Education_Foreign"]))
                    dgvDaoTao.Rows[i].Cells["Education_Foreign"].Value = "Nước ngoài";
                else
                    dgvDaoTao.Rows[i].Cells["Education_Foreign"].Value = "Trong nước";
                dgvDaoTao.Rows[i].Cells["Education_Place"].Value = _ds.Tables[0].Rows[i]["Education_Place"].ToString();
                if (_ds.Tables[0].Rows[i]["Education_FromDate"] != DBNull.Value)
                    dgvDaoTao.Rows[i].Cells["Education_FromDate"].Value = Convert.ToDateTime(_ds.Tables[0].Rows[i]["Education_FromDate"]).ToString("dd/MM/yyyy");
                else
                    dgvDaoTao.Rows[i].Cells["Education_FromDate"].Value = "";
                dgvDaoTao.Rows[i].Cells["Education_Time"].Value = _ds.Tables[0].Rows[i]["Education_Time"].ToString();
                if (_ds.Tables[0].Rows[i]["Education_DateIssue"] != DBNull.Value)
                    dgvDaoTao.Rows[i].Cells["Education_DateIssue"].Value = Convert.ToDateTime(_ds.Tables[0].Rows[i]["Education_DateIssue"]).ToString("dd/MM/yyyy");
                else
                    dgvDaoTao.Rows[i].Cells["Education_DateIssue"].Value = "";
                dgvDaoTao.Rows[i].Cells["Education_AuthorIssue"].Value = _ds.Tables[0].Rows[i]["Education_AuthorIssue"].ToString();
                dgvDaoTao.Rows[i].Cells["Education_Rank"].Value = _ds.Tables[0].Rows[i]["Education_Rank"].ToString();
                dgvDaoTao.Rows[i].Cells["Education_Description"].Value = _ds.Tables[0].Rows[i]["Education_Description"].ToString();
            }
        }
        private void btnEducation_New_Click(object sender, EventArgs e)
        {
            if (!_listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_employeeInfo.ID == 0)
            {
                MessageBox.Show("Bạn cần phải lưu thông tin nhân viên này trước!", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                frmEducationInfo f = new frmEducationInfo(0, _employeeInfo.ID, _listRole);
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    LoadEducation(_employeeID);
                }
            }
        }

        private void btnEducation_Edit_Click(object sender, EventArgs e)
        {
            if (dgvDaoTao.SelectedRows.Count > 0)
            {
                if (_listRole.Update || _listRole.View)
                {
                    Form f = new frmEducationInfo(Convert.ToInt32(dgvDaoTao.CurrentRow.Cells["Education_ID"].Value), Convert.ToInt32(dgvDaoTao.CurrentRow.Cells["Education_EmployeeID"].Value), _listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        LoadEducation(_employeeID);
                    }
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void btnEducation_Delete_Click(object sender, EventArgs e)
        {
            if (dgvDaoTao.SelectedRows.Count > 0)
            {
                if (!_listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxoa"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    EducationClient wcfEducation = Service.Education();
                    if (wcfEducation.Education_Delete(Convert.ToInt32(dgvDaoTao.CurrentRow.Cells["Education_ID"].Value)))
                    {
                        Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                        LoadEducation(_employeeID);
                    }
                    else
                    {
                        MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }

        private void dgvDaoTao_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnEducation_Edit_Click(null, null);
        }

        private void tstLuong_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void txtMedicalPlace_Leave(object sender, EventArgs e)
        {
            if (!_wcfHospital.Hospital_CheckExist(txtMedicalPlace.Text.Trim(), txtEmployee_HospitalRegionCode.Text))
            {
                frmHospitalList f = new frmHospitalList(true);
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    txtMedicalPlace.Text = f.HospitalCode;
                    txtHospitalName.Text = f.HospitalName;
                    txtEmployee_HospitalRegionCode.Text = f.HospitalRegionCode;
                }
            }
            else
            {
                HospitalInfo hptInfo = _wcfHospital.Hospital_GetInfoByCode(txtMedicalPlace.Text.Trim(), txtEmployee_HospitalRegionCode.Text);
                if( hptInfo!=null)
                    txtHospitalName.Text = hptInfo.Name;
            }
        }
     
        private void txtEmployee_MedicalRegionCode_Leave(object sender, EventArgs e)
        {
            if (!_wcfHospital.Hospital_CheckExist(txtMedicalPlace.Text.Trim(), txtEmployee_HospitalRegionCode.Text))
            {
                frmHospitalList f = new frmHospitalList(true);
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    txtMedicalPlace.Text = f.HospitalCode;
                    txtHospitalName.Text = f.HospitalName;
                    txtEmployee_HospitalRegionCode.Text = f.HospitalRegionCode;
                }
            }
            else
            {
                HospitalInfo hptInfo = _wcfHospital.Hospital_GetInfoByCode(txtMedicalPlace.Text.Trim(), txtEmployee_HospitalRegionCode.Text);
                if (hptInfo != null)
                    txtHospitalName.Text = hptInfo.Name;
            }
        }

        private void txtEmployee_IDCardNo_Validated(object sender, EventArgs e)
        {
            if (txtEmployee_IDCardNo.Text.Length != 9 && txtEmployee_IDCardNo.Text.Length != 12)
            {
                MessageBox.Show("Số chứng minh thư phải đủ 9 hoặc 12 ký tự");
                txtEmployee_IDCardNo.Focus();
                return;
            }
            //else
            //    //Check trùng CMT - bo di 21/06/2012, thay bang so so tam tu sinh
            //    if (_wcfEployee != null)
            //    {
            //        if (_wcfEployee.Employee_CheckIDCard(_employeeID, txtEmployee_IDCardNo.Text.Trim(), _BranchID) > 0)
            //        {
            //            MessageBox.Show("Số Chứng minh thư nhân dân này đã được sử dụng cho 1 nhân sự khác", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //            return ;
            //        }
            //    }
            //if (txtEmployee_BookNo.Text.Length != 10)
            //    txtEmployee_BookNo.Text = "A" + txtEmployee_IDCardNo.Text;
        }

       
    }
}
